Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
19 views

Python - Assignment 1

Uploaded by

binokad912
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Python - Assignment 1

Uploaded by

binokad912
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

K. K.

Wagh Institute of Engineering Education and Research, Nashik


(Autonomous from Academic Year 2022-23)
S. Y. B. Tech. Artificial Intelligence and Data Science
Pattern 2022 Semester: III
ADS222010: Python Programming Lab
Assignment No. 1

Problem Statement:
Write a python program that accepts seconds as input of type integer. The
program should convert seconds in hours, minutes and seconds. Output
should like this:
Enter seconds: 12200
Hours: 3
Minutes: 23
Seconds: 20

Prerequisites:
Hardware requirements: Desktop Computer / Laptop
Software requirements: Linux/windows O.S with Python
Python Feature:

1)Easy to read and write 2) Object-Oriented language


3)Large Standard library 4) Interpreted language
5)Dynamic memory allocation 6) Integrated
Python Execution:

Most Factory version of UBUNTU 18.04 and later comes with Python pre insalled.
To check version of Python use following command:
Python --version or python3 –version
To install python ,use the following command:
sudo apt-get update
sudo apt-get install python3.6

To run a Python script store in a ‘.py’ file in the command line, we have to write
‘python’ keyword before the file name in the command prompt.ex- python hello.py

Python Variables:

Python variables are simply containers for storing data values. Unlike other
languages, such as Java, Python has no command for declaring a variable, so you
create one the moment you first assign a value to it
Python Data Types:

There are different types of data types in Python. Some built-in Python data types are:

Numeric data types: int, float, complex


String data types: str
Sequence types: list, tuple, range
Binary types: bytes, bytearray, memoryview
Mapping data type: dict
Boolean type: bool
Set data types: set, frozenset

Assign Values to Multiple Variables in One Line:

Python assigns values from right to left. When assigning multiple variables in a single
line, different variable names are provided to the left of the assignment operator
separated by a comma
Ex-a, b = 4, 8
Python Comments:
Comments starts with a #, and Python will ignore them:
Multiline Comments-Since Python will ignore string literals that are not assigned to a
variable, you can add a multiline string (triple quotes) in your code, and place your
comment inside it:
Python Basic Input and Output:
In Python, we can simply use the print () function to print output.
Syntax of print ()- print (object= separator= end= file= flush=)
Ex- print ('Good Morning!')
Python User Input:
, we have to use the input () function to take input from the user and stored the user input in
the variable. ex - num = int (input ('Enter a number: '))

Python Operators:

python divides the operators in the following groups:


1. Arithmetic Operators
2. Comparison Operators
3. Logical Operators
4. Bitwise Operators
5. Assignment Operators
6. Identity Operators and Membership Operators

1)Arithmetic operator:

Python Arithmetic operators are used to perform basic mathematical operations like addition,
subtraction, multiplication, and division
2) Comparison Operators:
In Python Comparison of Relational operators compares the values. It either
returns True or False according to the condition.
3) Logical Operators in Python:
Python Logical operators perform Logical AND, Logical OR, and Logical NOT operations. It
is used to combine conditional statements.

4) Bitwise Operators:
Python Bitwise operators act on bits and perform bit-by-bit operations. These are used to
operate on binary numbers.

5) Assignment Operators:
Python Assignment operators are used to assign values to the variables.

6) Identity Operators:
In Python, is and is not are the identity operators both are used to check if two values are
located on the same part of the memory. Two variables that are equal do not imply that they
are identical.

7) Membership Operators:
In Python, in and not in are the membership operators that are used to test whether a
value or variable is in a sequence.

Python Operators Precedence Table:

Operator Description
:= Assignment expression
lambda Lambda expression
if-else Conditional expression
or Boolean OR
and Boolean AND
not x Boolean NOT
in, not in, is, is not, <, <=, >, >=, !=, == Comparisons, membership and identity operators
| Bitwise OR
^ Bitwise XOR
& Bitwise AND
<<, >> Left and right Shifts
+, – Addition and subtraction
Multiplication, matrix multiplication, division, floor
*, @, /, //, %
division, remainder
+x, -x, ~x Unary plus, Unary minus, bitwise NOT
** Exponentiation
await x Await expression
x[index], x[index], x(arguments…),
Subscription, slicing, call, attribute reference
x.attribute
Operator Description
() Parentheses (Highest precedence)

Algorithm:

Test Case:
Enter seconds: 12200
Hours: 3 Minutes: 23
Seconds: 20

Discussion and Conclusion:


Hence by using Python, I have implemented this lab,

You might also like