Python Lab 5: if statements with else and elif 1. Write an if statement to determine if a number is divisible by 5. Ask the user to enter a number. Determine if the number is divisible by 5. if (number % 5 == 0): print (str(number) + ' is divisible by 5') 2. Write an if/else statement. An else statement can follow an if statement. The code in an else statement is executed if the expression in the if statement is false. if (number % 5 == 0): print (str(number) + ' is divisible by 5') else: print (str(number) +' is divisible by 5') Notice that an else statement does not have a Boolean expression. Write an additional if/else statement to see if the number is divisible by 2. Test your code with many different inputs. 3. Write an iflelif/else The command elif can be used to make a series of if statements more efficient. As soon as one of the expressions is true, the other ones are skipped. elif is short for 'else if. sequence. Ask the user to enter a State/Province name, and print out the capital of that state. Your code should handle at least 6 different inputs. Use an if/elif/else structure if (state == 'Wisconsin'): print ('Madison') elif (state == 'Colorado)': print('Denver') else: print ('I do not know that one') Test your code with many different input values. 4. Use elif in a function definition. At a certain public pool, entrance prices are as follows: Under 2 years: free, Age 2-11: $3, Age 11-60: $6, Over 60: $4 Complete a function that takes the age in years as input and returns the price in dollars (without the dollar sign). def pool_admission(age): if (age < 2): return e elif (age < 12): return 3 Notice that elif reduces possibilities and makes the code easier to read.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section5.7: Do While Loops
Problem 3E: (Misc. application) a. Write a program to reverse the digits of a positive integer number. For...
icon
Related questions
icon
Concept explainers
Question
Python Lab 5: if statements with else and elif
1. Write an if statement to
Ask the user to enter a number. Determine if the number is divisible by 5.
if (number % 5 == 0):
print (str(number) + ' is divisible by 5')
determine if a number is
divisible by 5.
2. Write an if/else statement.
An else statement can follow an if statement. The code in an else
statement is executed if the expression in the if statement is false.
if (number % 5 == 0):
print (str(number) +
' is divisible by 5')
else:
print (str(number) + ' is divisible by 5')
Notice that an else statement does not have a Boolean expression.
Write an additional iflelse statement to see if the number is divisible by 2.
Test your code with many different inputs.
3. Write an if/elif/else
The command elif can be used to make a series of if statements more
efficient. As soon as one of the expressions is true, the other ones are
skipped. elif is short for 'else if.
sequence.
Ask the user to enter a State/Province name, and print out the capital of
that state. Your code should handle at least 6 different inputs. Use an
if/eliflelse structure
if (state == 'Wisconsin'):
print ('Madison')
elif (state == 'Colorado)':
print('Denver')
else:
print ('I do not know that one')
Test your code with many different input values.
4. Use elif in a function
At a certain public pool, entrance prices are as follows:
Under 2 years: free, Age 2-11: $3, Age 11-60: $6, Over 60: $4
Complete a function that takes the age in years as input and returns the
price in dollars (without the dollar sign).
definition.
def pool_admission (age):
if (age < 2):
return e
elif (age < 12):
return 3
Notice that elif reduces possibilities and makes the code easier to read.
Transcribed Image Text:Python Lab 5: if statements with else and elif 1. Write an if statement to Ask the user to enter a number. Determine if the number is divisible by 5. if (number % 5 == 0): print (str(number) + ' is divisible by 5') determine if a number is divisible by 5. 2. Write an if/else statement. An else statement can follow an if statement. The code in an else statement is executed if the expression in the if statement is false. if (number % 5 == 0): print (str(number) + ' is divisible by 5') else: print (str(number) + ' is divisible by 5') Notice that an else statement does not have a Boolean expression. Write an additional iflelse statement to see if the number is divisible by 2. Test your code with many different inputs. 3. Write an if/elif/else The command elif can be used to make a series of if statements more efficient. As soon as one of the expressions is true, the other ones are skipped. elif is short for 'else if. sequence. Ask the user to enter a State/Province name, and print out the capital of that state. Your code should handle at least 6 different inputs. Use an if/eliflelse structure if (state == 'Wisconsin'): print ('Madison') elif (state == 'Colorado)': print('Denver') else: print ('I do not know that one') Test your code with many different input values. 4. Use elif in a function At a certain public pool, entrance prices are as follows: Under 2 years: free, Age 2-11: $3, Age 11-60: $6, Over 60: $4 Complete a function that takes the age in years as input and returns the price in dollars (without the dollar sign). definition. def pool_admission (age): if (age < 2): return e elif (age < 12): return 3 Notice that elif reduces possibilities and makes the code easier to read.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 15 images

Blurred answer
Knowledge Booster
Control Structure
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning