Python - Assignment 1
Python - Assignment 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:
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:
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:
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.
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