Assignment#1 AI
Assignment#1 AI
Roll NO:BSOR-1738-18(Regular)
Practice
,
It will print 1 0 0 because “ ” for separate the value after, it takes only
one zero
47name='Pakistan'
Output is Error because we cannot use numerical value as a first letter of
variable name.
name@= 'Pakistan'
Output is Error because we cannot use special character in variable in this
question @ is use.
Class = 'Pakistan'
Output is Error because we cannot use key words as a variable name.
● print200+323-435
print(200+323-435)
output88
● print(2+1)*(8-6)
print((2+1)*(8-6))
6
● whatwillbetheoutputof1andFalse
?
Assignment
Q#1(15marks)
print(2**1+1)
output 3
print(3*1**3)
output3
write a program which take age & height from user and concate it three time.
age=input("age")
height=input("height")
print((age, height)*3)
bool
Q#2(10marks)
X == y # x is equal to y
X != y # x is not equal to y
x is y #x is same as y
Q#3(20marks)
.
● Write a program to Prompt for a score between 0 . 0 and 1.0.If the score is out of range print
eror if the score is between 0.0 and 1.0 print a grade using the following table:
Score Grade
>=0.9A
>=0.8B
>=0.7C
>=0.6D
<0.6F
Solution
If score>=0.9:
print("GradeA")
print("Grade:B")
print("Grade:c")
print("Grade:D")
elif score<0.6:
print("Grade:F")
● Write a program using try and except so that your program handles non numeric input gracefully but
printing a message and exiting the program.The following shows two execution of the program.
n = int(input("hours"))
Enter hours:20
● Write a program that accept integer a (if user pass string throw exception with message)and
Calculate a+a^2+a^3.
if b == int :
Q#4(5marks)
1. 2.
x=1 x=6
y=0 y=0
x>=2and(x/y)>2 x>=2and(x/y)>2
output:False Output:error
● Why first program is giving false and 2nd is giving error
Answer
First program is giving false because And operator use .it give true value when both condition
are true. In given first program first condition 1 > = 2 is false control not transfer to the 2nd
condition and give answer false.
Second program is giving Error because And operator use. It give true value when both
condition are true .In given 2nd program first condition 6 > = 2 is true but second condition is
infinite logical error (1/0)> 2 there for error occur.
Guard Evaluation
x=1
y=0
x >= 2 and y != 0and (x/y)>2
● What will happen if you execute x>=2 and (x/y) >2 and y! = 0(related to Guard Evaluation)
output
False
Because in this program use And operator. It gives true value when all condition are true. But in this
situation first condition is false 1>=2 it not execute all condition and give false.