2021-civ-73
November 21, 2024
[1]: x = 2
y = 4
print (x*y)
[2]: x = 5 + 7
print (x)
type (x)
12
[2]: int
[4]: x = 'Hello' + 'Wrold'
print (x)
type (x)
HelloWrold
[4]: str
[5]: x = 98.6
type (x)
[5]: float
[6]: x = 2.3 * 2.3
print (x)
5.289999999999999
[7]: x = 10/2
print (x)
5.0
1
[1]: x = 42
f = float(x)
type (x)
f = float(x)
print (f)
42.0
[9]: x = '123'
y = int(x) + 1
print (y)
124
[11]: x = input('Who are you?')
print('Welcome',x)
Who are you? Intizar Mehdi
Welcome Intizar Mehdi
[15]: #Addition of two numbers
x = input('1st Number =')
y = input('2nd Number =')
z = int(x) + int(y)
print('Sum =', z)
1st Number = 12
2nd Number = 13
Sum = 25
[17]: x = input('enter No.')
if int(x) < 5 :
# : will indent
print ('small')
elif int(x) > 10 :
print ('large')
else :
print ('medium')
enter No. 58
large
[21]: #start
x = input('No. 1 =')
y = input('No. 2 =')
if int(x)>int(y):
2
print ('No. 1 > No. 2')
else:
print ('No. 2 > No. 1')
#End
No. 1 = 23
No. 2 = 32
No. 2 > No. 1
[23]: #Get input from user
x = input('Enter a No. =')
if int(x)==5:
print('x is 5')
else:
print('x is not 5')
#End
Enter a No. = 5
x is 5
[40]: #Calculator of 2 digits
x = input('1st No.')
y = input('2nd No.')
x = float(x)
y = float(y)
sum = x + y
subtract = x - y
divide = x/y
Multiply = x * y
#operation as opt
print ('waht do you want', 'sum', 'subtract', 'divide', 'Multiply')
Opt = input('Enter Operation')
if Opt == 'sum' :
print (sum)
elif Opt == 'subtract':
print (subtract)
elif Opt == 'divide':
print (divide)
elif Opt == 'Multiply':
print (Multiply)
else:
print('Invalid Operation')
1st No. 2
2nd No. 4
waht do you want sum subtract divide Multiply
3
Enter Operation adf
Invalid Operation
[6]: #Program of Flow chart
x = input('Enter a Number')
y = int(x)
if y == -1 :
print ('Not Valid')
elif y > 0 :
print ('ok')
else :
print ('Enter a +ve No. only')
Enter a Number -2
Enter a +ve No. only
[15]: x = input ('Enter a Number')
try:
y = int (x)
except :
y = -1
if y > 0 :
print ('ok')
else :
print ('Enter a +ve No.')
Enter a Number -4
Enter a +ve No.
[26]: #paying the payment of Salesman
print ('pay per hr = 10$')
print ('working hrs per week = 40')
x = input('Enter no. of working hrs')
if int(x)<=40 and int(x)>0:
y = int(x) * 10
print (y)
elif int(x)>40:
y = 40*10+ (int(x)-40)*(1.5)*(10)
print (y)
pay per hr = 10$
working hrs per week = 40
Enter no. of working hrs 50
550.0
4
[41]: #Program for calculating the total marks, % of students
try:
x = input('Enter the no. of Maths')
y = input('Enter the no. of English')
z = input('Enter the no. of Urdu')
if int(x) > 100 or int(y) > 100 or int(z)>100:
print('Enter marks from 0 to 100')
elif int(x) < 0 or int(y) < 0 or int(z)<0:
print('Enter marks from 0 to 100')
else:
Total = int(x)+int(y)+int(z)
per = (Total/300)*100
print ('Total marks =',Total)
print ('%age =', per)
if per >= 90:
print('Grade: A')
elif per >= 80:
print ('Grade: B')
elif per >= 70:
print ('Grade: C')
elif per >= 60:
print ('Grade: D')
elif per < 60:
print ('Grade: F')
except:
print ('Enter a Numeric No.')
Enter the no. of Maths 101
Enter the no. of English 45
Enter the no. of Urdu 56
Enter marks from 0 to 100
[43]: def print_hello() :
print ('Hello')
print_hello ()
Hello
[44]: def number_classification (n):
if n > 0:
return 'no. is positive'
elif n < 0:
return 'no. if negative'
else:
return 'no. is zero'
number_classification (6)
5
[44]: 'no. is positive'
[45]: def add (a,b):
return a + b
add(2,2)
[45]: 4
[47]: n = 5
while n > 0:
print (n)
n = n - 1
5
4
3
2
1
[48]: for i in (5,4,3,2,1):
print (i)
5
4
3
2
1
[ ]: