0% found this document useful (0 votes)
2 views5 pages

Lab Test Sample Questions Set I

This document contains a set of lab test sample questions focused on Python programming. It includes tasks such as swapping variable values, checking for even or odd numbers, determining leap years, and calculating sums and factorials. The test is designed to be completed in one hour and solutions should be submitted as a .py file.

Uploaded by

Chit Su Hlaing
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views5 pages

Lab Test Sample Questions Set I

This document contains a set of lab test sample questions focused on Python programming. It includes tasks such as swapping variable values, checking for even or odd numbers, determining leap years, and calculating sums and factorials. The test is designed to be completed in one hour and solutions should be submitted as a .py file.

Uploaded by

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

Lab Test Sample Questions Set I

• Test duration: 1 hour.


• Submit your solutions as a .py file.

1. Write a Python program to swap the values of two variables using a


temp variable.
Solution:
x=100
y=200
temp=x
x=y
y=temp
print(“x=”,x)
print(“y=”,y)

2. Create a variable x with value 5. Double its value and print the result.

3. Convert the integer 100 into a string and print its type.
4. Write a Python program to check if a number entered by the user is
even or odd.

5. Create a program that checks if a year entered by the user is a leap


year.

6. Write a Python script to compare three numbers and print the largest
one.
7. Write a for loop to calculate the sum of numbers from 1 to 50.

8. Create a Python program that prints the multiplication table of 7.

9. Write a Python script to iterate over a list of names ["Alice", "Bob",


"Charlie"] and print each name in uppercase.

10. Write a Python program to find the factorial of a number using a


while loop.
11. Create a program that keeps asking the user for a password until
they enter "12345".
Solution:
status=True
while status==True:
password = input("Enter password: ")
if password == "12345":
print("Access granted")
status=False

12. Write a Python script to calculate the sum of all even numbers
between 1 and 20 using a while loop.

13. Write a Python program to check if a string is a palindrome.


14. Create a program to count the number of vowels in the string
"hello world".

15. Write a program to calculate the sum of all numbers divisible by


3 and 5 between 1 and 100.

You might also like