0% found this document useful (0 votes)
10 views

Assignment#1 AI

Uploaded by

Bushra Munir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Assignment#1 AI

Uploaded by

Bushra Munir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Bushra Munir

Roll NO:BSOR-1738-18(Regular)
Practice

● Print two or more values using single statement


print(7+9)
● Print name of your country
print("Pakistan")
● Print your date of birth
print("13-jun-2000")
● Print your name, age and height using one print statement
print("Name=Bushra ",”age=21","height=5.1")
● What will happen if you print 1million using following statement
print(1,00,000)
● What will happen

,
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

● what will be the output of 0 or True

● whatwillbetheoutputof1andFalse

?
Assignment

Q#1(15marks)

● write output of the following commands without executing it


print(2*(3-1))
output 4
print((1+1)**(5-2))
output 8

print(2**1+1)
output 3

print(3*1**3)
output3

print your name 10 times


a = “bushra”
print(a*10)

write a program which take age & height from user and concate it three time.
age=input("age")
height=input("height")
print((age, height)*3)

what is the type of False

bool
Q#2(10marks)

X == y # x is equal to y

X != y # x is not equal to y

x> y # x is greater than to y

x< y # x is less than y

x>=y# x is greater than or equal to y

x<=y # x is less than or equal to y

x is y #x is same as y

x is not y #x is not same as y

● if x=10,y=10,which of the above statement will return True


x==y
x>=y
x<=y
x is y

● if x=10,y=30,which of the above statement will return False


x==y
x>=y
x is y
x>y

● write the comparison operators which are common in above two


x == y
x>=y
x is 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

Score = float(input("Enter your marks"))

If score>=0.9:

print("GradeA")

elif score>= 0.8 and score<0.9:

print("Grade:B")

elif score>=0.7 and score< 0.8:

print("Grade:c")

elif score>=0. 6and score<0.7:

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

Enter rate : nine

Error pleasant enter numeric input

Enter hours : forty

Error pleasant enter numeric input

● Write a program that accept integer a (if user pass string throw exception with message)and
Calculate a+a^2+a^3.

A = input ("in put any value")


b=type (a)

if b == int :

print (a+ a**2+a**3)

● Write a program take radius from user and return area.

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.

You might also like