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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education