0% found this document useful (0 votes)
28 views7 pages

Python Revision Questions and Answers

Uploaded by

Nimra
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)
28 views7 pages

Python Revision Questions and Answers

Uploaded by

Nimra
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

Python Revision Questions

i) Python was first released in:


a) 1989 b) 1991 c) 1995
Answer: b) 1991
ii) What will be the output of print(2 ** 3)?
a) 6 b) 8 c) 9
Answer: b) 8
iii) Which of the following is not a valid variable name in Python?
a) my_var b) 2ndVar c) _myVar
Answer: b) 2ndVar
iv) What will be the output of the following code?
x = 10
if x > 5:
print("Greater than 5")
elif x < 5:
print("Less than 5")
else:
print("Equal to 5")
a) Greater than 5 b) Less than 5 c) Equal to 5
Answer: a) Greater than 5
v) What will the following code output?
y = 20
if y > 10 and y < 30:
print("In range")
else:
print("Out of range")
a) In range b) Out of range
Answer: a) In range
vi) Which operator is used to check if two values are not equal?
a) != b) <=> c) <>
Answer: a) !=
vii) What is the output of the following code?
x = True
y = False
print(x and y)
a) True b) False c) None
Answer: b) False
viii) Predict the output (Values entered by user are 20 and 30):
a=int(input("Enter first no:"))
b=int(input("Enter Second no:"))
print("a=" + a + " b=" + b + " a+b=" + a+b)
a) 2030 b) 50 c) a=20 b=30 a+b=50
Answer: Error (string + int mismatch, needs str())
ix) What will be the datatype of variable a in the following
statement?
a=input("Enter your age:")
a) int b) float c) string
Answer: c) string
x) What does the following code output?
num = 15
if num % 2 == 0:
print("Even")
elif num % 2 != 0:
print("Odd")
a) Even b) Odd
Answer: b) Odd
xi) Which command is used to move the turtle forward by 100
steps?
a) forward(100) b) move(100) c) step(100)
Answer: a) forward(100)
xii) Which turtle command turns the turtle 90 degrees to the
right?
a) rt(90) b) right(90) c) turn(90)
Answer: a) rt(90) or b) right(90)
xiii) What does the command circle(50) do in turtle?
a) Draws a circle of radius 50 b) Draws a circle of diameter 50 c)
Moves turtle forward 50
Answer: a) Draws a circle of radius 50
xiv) Which command is used to change the turtle’s drawing color
to red?
a) pen("red") b) color("red") c) setcolor("red")
Answer: b) color("red")
xv) What will be the output of the following code?
def greet():
print("Hello Students!")
greet()
a) Nothing b) Error c) Hello Students!
Answer: c) Hello Students!
xvi) Which keyword is used in Python to define a function?
a) def b) func c) function
Answer: a) def
xvii) What is the output of this code?
def add(a, b):
return a + b
print(add(5, 3))
a) 53 b) 8 c) Error
Answer: b) 8
xviii) What will this turtle program draw?
import turtle
for i in range(4):
[Link](100)
[Link](90)
a) Circle b) Square c) Triangle
Answer: b) Square
xix) Which function stops the turtle graphics window from closing
immediately?
a) stop() b) exit() c) done()
Answer: c) done()
xx) What will this code output?
def square(x):
return x * x
print(square(6))
a) 12 b) 36 c) 6
Answer: b) 36
Programs in Python

Codes for ATM program


cardnum=123456
pin=9876
balance=5000

cn=int(input("Enter card number: "))


pn=int(input("Enter pin number: "))

def deposit():
global balance
amt=int(input("Enter deposit value: "))
balance=balance+amt
print("Your new balance is ", balance)

def withdraw():
global balance
amt=int(input("Enter withdraw value: "))
if amt<=balance:
balance=balance-amt
print("Your new balance is ", balance)
else:
print("Insufficient balance")
print("Your balance is ", balance)

def checkbal():
global balance
print("Your balance is ", balance)

if(cardnum==cn and pin==pn):


option=int(input("Choose option: \n [Link] \n [Link] \n [Link]
balance \n"))
if (option==1):
deposit()
elif(option==2):
withdraw()
elif(option==3):
checkbal()
else:
print("Request does not match \n Thank you")

else:
print("Please check correct card number and pin")
Codes for Calculating the discount
# Function to calculate the discount
def calculate_discount(price):
if price >= 500:
discount = 0.30 # 30% discount for prices 500 or more
elif price >= 200:
discount = 0.20 # 20% discount for prices between 200 and 499
elif price >= 100:
discount = 0.10 # 10% discount for prices between 100 and 199
else:
discount = 0.00 # No discount for prices less than 100

return discount

# Function to display the discount details


def display_discount_details(price, discount):
discount_amount = price * discount
final_price = price - discount_amount

print(f"Original Price: ₹{price:.2f}")


print(f"Discount Amount: ₹{discount_amount:.2f}")
print(f"Final Price After Discount: ₹{final_price:.2f}")

# Main function to get input from user and calculate the discount
def main():
# Take price input from the user
price = float(input("Enter the price of the product (in ₹): "))

# Calculate the discount based on the price


discount = calculate_discount(price)

# Display the discount details


display_discount_details(price, discount)

# Run the main function


if __name__ == "__main__":
main()

Codes for drawing a Smiley


import turtle
[Link](10)
[Link](10)
[Link]()
[Link](0,-200)
[Link]()
[Link]("yellow")
turtle.begin_fill()
[Link](200)
turtle.end_fill()

[Link]()
[Link](-100,50)
[Link]()
[Link]("white")
turtle.begin_fill()
[Link](30)
turtle.end_fill()

[Link]()
[Link](100,50)
[Link]()
[Link]("white")
turtle.begin_fill()
[Link](30)
turtle.end_fill()

[Link]()
[Link](0,50)
[Link]()
[Link](-90)
[Link](100)

[Link]()
[Link](-80,-100)
[Link]()
[Link](-45)
[Link](120,90)

You might also like