worksheet 3 for class XI IF ELSE AND ELIF

 


Part1:Fill in the Blanks

Complete the following code snippets by filling in the blanks:

  1. python

    age = 20
    if age ___ 18:
    print("You are an adult.")
    else:
    print("You are a minor.")
  2. python

    score = 75
    if score ___ 90:
    print("Grade: A")
    elif score ___ 80:
    print("Grade: B")
    elif score ___ 70:
    print("Grade: C")
    else:
    print("Grade: D")

Part 2: Write Your Own

Write Python code for the following scenarios:

  1. Even or Odd:

    • Prompt the user to enter a number.
    • Print "Even" if the number is even, and "Odd" if the number is odd.
  2. Temperature Check:

    • Prompt the user to enter the current temperature in Fahrenheit.
    • Print "It's hot!" if the temperature is above 85, "It's warm." if it's between 60 and 85, and "It's cold!" if it's below 60.

Part 3: Debugging Practice

Find and fix the errors in the following code:

  1. python
    number = 10
    if number = 10:
    print("Number is 10")
  2. python

    score = 85
    if score > 90:
    print("Excellent")
    elif score > 75
    print("Good")
    else:
    print("Needs Improvement")

Part 4: Challenging Problems

  1. FizzBuzz:

    • Write a program that take input from the user between 1 to 20.
    • For multiples of three print "Fizz" instead of the number.
    • For multiples of five print "Buzz".
    • For numbers which are multiples of both three and five print "FizzBuzz".
  2. Age Group:

    • Prompt the user to enter their age.
    • Print "Child" if the age is less than 13, "Teenager" if the age is between 13 and 19, "Adult" if the age is between 20 and 59, and "Senior" if the age is 60 or above.

Post a Comment

0 Comments