SANJEEV SHARMA Practical Work Python Programming …
Q No. Q1
Q2 Q3 Q4 (a)
Q4(b)
Python Codes
Practical Work ? Python Programming Language Output
#Basic Operators in Python print(3-10**2+99/11) print(3-100+99//11) print(3-100+9.0) print(-97+9.0) # Conversion of Integer to Float print(3.25+2) # Use of int() function print("Fractional String to Integer",int("3.4")) print("Integer String to Integer",int("3")) # Use of max(),len() function T=(10,12,43,29) print(T[1]) print(len(T)) print(max(T)) T[1]=29 # Error because tuple is Immutable # Tuple example T=(1)# This will creates a Variable T with value 1 T=T+2 print(T) """ if you want to creates a tuple with single value then you need to insert a comma after that value """ T=(1,)#This will creates a Tuple T with value 1 T = T + 2 # Error because T is now a Tuple
-88.0 -88 -88.0 -88.0
5.25
Fractional String to Integer 3.4
Integer String to Integer 3 12 4 43
Error
3
SANJEEV SHARMA
Q5(a)
# Find the Data Type of Variable # type() method is used for finding the datatype x=10 print(type(x)) x=10.5 print(type(x)) x="Palampur" print(type(x))
Q5(b) # Mathematical Operations on String First_Name = "Karan" Last_Name = "Kumar"
T= (1) Error
print(First_Name + Last_Name) # Addition of Two Strings
# Addign a Blank Space between two Strings print(First_Name +" "+Last_Name) # Addition of Three Strings
KaranKumar
# We can Multiply a String with an Integer print(First_Name * 5)# This will repeat this string for Five times
Karan Kumar
print(First_Name - Last_Name)# Error Substraction is not allowed print(First_Name *Last_Name)# Error Multiplication of two strings is not allowed print(First_Name /Last_Name)# Error Division of two strings is not allowed
KaranKaranKaranKaranKaran
Q5(c) # Variables Declaration and Initialization
# Method One
x =10 y =20 print("X = :",x , "Y = ",y)
# Method Two x , y = 30 ,40 print("X = :",x , "Y = ",y)
# Interchanging the Values of variable x , y = y ,x print("X = :",x , "Y = ",y)
Q5(d) # Types of Strings in Python x = "Single Line String with double quotes" x1 = 'Single Line String with single quote'
y = """Multiline String In Python with triple double quotes"""
y1 = '''Multiline String In Python with triple single quotes'''
z = "Printing Quotes inside a 'String' " z1 = '''Printing Quotes inside a "String" '''
print(x) print(x1) print(y) print(y1)
X = : 10 Y = 20
X = : 30 Y = 40
X = : 40 Y = 30 Single Line String with double quotes Single Line String with single quote Multiline String In Python with triple double quotes Multiline String In Python with triple single quotes Printing Single Quotes inside a 'String' Printing Double Quotes inside a "String"
print(z) print(z1)
Q6(a)
# range() method """ The range function in Python generates a random list of numbers which is generally used to iterate over items using for loops.
range(Start [Optional], End ,Step[Optional]) Default Start =0 Default Step=1 It will generate a sequence of numbers from Start to End-1 """ # Use of range() function for n in range(1,5,1): # With all arguments
print("N =:",n) for p in range(5,1): # Without Start argument
print("P =:",p) for q in range(5): # Without Start and End arguments
print("Q =:",q) for r in range(1,10,2): # With Step value 2
print("R =:",r) for s in range(5,1,-1): # With Step value -1
print("S =:",s)
Q6(b) # if condition in Python """
N =: 1 N =: 2 N =: 3 N =: 4
P =: 1 P =: 2 P =: 3 P =: 4
Q =: 0 Q =: 1 Q =: 2 Q =: 3 Q =: 4
R =: 1 R =: 3 R =: 5 R =: 7 R =: 9
S =: 5 S =: 4 S =: 3 S =: 2
Please enter today day number [1-7]: 1 Today is Monday
Perhaps the most well-known statement type is the if statement.
#Syntax of if condition The general Python syntax for a simple if condition is:
if condition : indented Statement Block For True Condition
If the condition is true, then do the indented statements. If the condition is not true, then skip the indented statements.
""" # Simple if condition x = int(input("Please enter today day number [1-7]: ")) if x == 1:
print("Today is Monday")
# if condition with else #Syntax of if -else condition
""" The general Python syntax for a if-else condition is:
if condition : indented Statement Block For True Condition
else: indented Statement Block For False Condition
"""
Please enter today day number [1-7]: 2 Else Statement Output - Wrong Input
Please enter today day number [1-7]: 5 Friday End of the program
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- sanjeev sharma practical work python programming
- python a simple tutorial
- lecture 2 python data type and variables data data type
- declaring string variable in python
- lab parse different data types with python
- working with files in python
- lesson1 getting started with idle strings variables
- python variable types rxjs ggplot2 python data
- python programming 1 variables loops and input output