CSC 110 Python Coding II Python Lab 1: 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...

1 answer below »
See attached


CSC 110 Python Coding II Python Lab 1: 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 if/elif/else sequence. 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'. 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="" 0="" elif="" (age="">< 12):="" return="" 3="" notice="" that="" elif="" reduces="" possibilities="" and="" makes="" the="" code="" easier="" to="" read.="" python="" lab="" 2:="" while="" loops="" 1.="" the="" while="" statement="" allows="" the="" commands="" with="" the="" body="" of="" the="" loop="" to="" be="" repeated,="" as="" long="" as="" a="" certain="" condition="" is="" true.="" ask="" the="" user="" to="" enter="" an="" integer.="" store="" the="" value="" in="" x.="" then="" add="" this="" code="" which="" counts="" down.="" while="" (x=""> 0): print x x = x - 1 print ('blastoff!!') enter an integer: 3 3 2 1 blastoff!! 2. Modify the loop to print out whether a number is even or odd. An even number is divisible by 2, and an odd number is not. enter an integer: 3 3 is odd 2 is even 1 is odd blastoff!! 3. Ask the user to enter in the amount of decrease. Use this value in your loop. enter an integer: 11 enter decrease: 4 11 is odd 7 is odd 3 is odd blastoff!! 4. Beware infinite loops! Take out the line which decreases x. What happens? Then put the line back in. 5. Write a different loop to print out words until the word has a length less than 5. The len() function returns the length of a string. print ( word, 'has', len(word), 'letters') enter a word: hello hello has 5 letters enter a word: yellow yellow has 6 letters enter a word: dog goodbye 6. There are several different ways to write the code for the problem above. Discuss with your peers, or explore other possibilities on your own. 7. Write a while loop that counts from 10 to 100 in decimal, binary, and hex. 10 0b1010 0xa 11 0b1011 0xb 12 0b1100 0xc 13 0b1101 0xd 14 0b1110 0xe 15 0b1111 0xf 2
Answered Same DayJul 24, 2022

Answer To: CSC 110 Python Coding II Python Lab 1: if statements with else and elif 1. Write an if statement to...

Aditi answered on Jul 25 2022
80 Votes
ASSIGNMENT
Python Lab1:
1.
Program Instruction:
· The user is prompted to input a number.
· If
the number is divisible by 5 then a message saying the number is divisible by 5 is printed.
· If the number is not divisible by 5 then nothing is printed.
2.
Program Instruction:
· The user is prompted to input a number.
· If the input number when divided by 2 return 0 as remainder then a message saying the number is divisible by 2 is printed.
· If the number is not divisible by 2 then a message saying the number is not divisible by 2 is printed.
3.
Program Instruction:
· The user is prompted to input a state or a province.
· If the state is valid then the capital for the state is printed.
· Else a message saying "I...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here