Copy
Copy
1 What is a variable?
Ans variable are the name used to store values at computer memory locations in a program.
Ans len(name)
Ans “4+1”
it will return true if the string we want to find is there in the given string
Ans
// did not understand the expression
11 Under what circumstances does the expression 18 <= age < 65 evaluate to True ?
Ans the age should be in range [18,65)
Coding Exercises
Ans
fizzyNumber = int(input("enter the fizzy number "))
if(fizzyNumber % 3 == 0 and fizzyNumber % 5 ==0):
print("FizzBuzz")
elif(fizzyNumber % 3 == 0):
print("Fizz")
elif(fizzyNumber % 5 == 0):
print("Buzz")
else:
print(fizzyNumber)
3 Write a python program for checking the speed of drivers. This function should have one
parameter: speed.
If speed is less than 70, it should print “Ok”.
Otherwise, for every 5km above the speed limit (70), it should give the driver one demerit point
and print the total number of demerit points. For example, if the speed is 80, it should print:
“Points: 2”.
If the driver gets more than 12 points, the code should print: “License suspended”
def speedCheck(speed):
if(speed <= 70):
print("Ok")
else:
extraSpeed = speed - 70
demeritPoints = extraSpeed//5
if(demeritPoints == 12):
print("License suspended")
else:
print("Points: {}".format(demeritPoints))
speed = int(input("enter speed "))
speedCheck(speed)
4 Write a python program called showNumbers that takes an input called limit. It should print all
the numbers between 0 and limit with a label to identify the even and odd numbers. For
example, if the limit is 3, it should print:
0 EVEN
1 ODD
2 EVEN
3 ODD
Ans
5 Write a python program that returns the sum of multiples of 3 and 5 between 0 and limit
(parameter). For example, if limit is 20, it should return the sum of 3, 5, 6, 9, 10, 12, 15, 18, 20.
Ans
limit = int(input("enter limit "))
sumOfMultipleOf3And5=0
for i in range(3,limit+1):
if(i%3 ==0 or i%5==0):
sumOfMultipleOf3And5 = sumOfMultipleOf3And5 + i
print(sumOfMultipleOf3And5)
6 Write a python program called show_stars(rows). If rows is 5, it should print the following:
*
**
***
****
*****
Ans
rows = 5
for i in range(0,rows):
for k in range(0,i+1):
print("*",end="")
print(end="\n")
7 Write a python that prints all the prime numbers between 0 and limit where limit is a
parameter.