Question

In: Computer Science

4.9 Branching Practice - Python Exercise #Write the code for the following # Exercise 1 #...

4.9 Branching Practice - Python Exercise

#Write the code for the following
# Exercise 1
# Ask user for a number using an input statement (no prompt) & assign the input to a variable
# Convert the user entry to an integer and assign it to a variable
# Condition: user entry is greater than zero
# Action: display the following word on screen: positive

# Exercise 2
# Ask user for a number using an input statement (no prompt) & assign the input to a variable
# Convert user entry to an integer and assign it to a variable
# Condition: user entry is greater than 99
# Action: display the following word on screen: hundreds

# Exercise 3
# Ask user for a number using an input statement (no prompt) & assign the input to a variable
# Convert user entry to an integer and assign it to a variable
# Condition: user entry is less than zero
# Action: display the following word on screen: negative

# Exercise 4
# Ask user for a number using an input statement (no prompt) & assign the input to a variable
# Convert the user entry to an integer and assign it to a variable
# Condition: user entry is less than zero
# Action: display the following word on screen: negative
# All other conditions
# Action: display the following word on screen: positive

# Exercise 5
# Ask user for a number using an input statement (no prompt) & assign the input to a variable
# Convert user entry to an integer and assign it to a variable
# Condition: user entry is greater than 99
# Action: display the following word on screen: hundreds
# All other conditions
# Action: display the following words on screen: low number

# Exercise 6
# Ask user for a number using an input statement (no prompt) & assign the input to a variable
# Convert user entry to an integer and assign it to a variable
# Condition: user entry is equal to 2001
# Action: display the following words on screen: Twin Towers
# Condition: user entry is equal to 2008
# Action: display the following words on screen: Great Recession
# Condition: user entry is equal to 2017
# Action: display the following words on screen: Hurricane Maria
# All other conditions
# Action: display the words No Disasters on screen

# Exercise 7
# Ask user for a number using an input statement (no prompt) & assign the input to a variable
# Convert user entry to an integer and assign it to a variable
# Condition: user entry is equal to 2001
# Action: display the following phrase on screen using a combination of the user entry and exact text: 2001 : Twin Towers
# Condition: user entry is equal to 2008
# Action: display the following phrase on screen using a combination of the user entry and exact text: 2008 : Great Recession
# Condition: user entry is equal to 2017
# Action: display the following phrase on screen using a combination of the user entry and exact text: 2017 : Hurricane Maria
# All other conditions
# Action: display the following phrase on screen using exact text only: No disasters!

Solutions

Expert Solution

ANSWERES:-

EXERCISE 1:-

#exercise 1
num=input('Enter a number :')

#converting entry to integer
convertedNum=int(num)
if(convertedNum>0):
    print("Positive")

SCREENSHOT OF THE CODE AND SAMPLE OUTPUT:-

EXERCISE 2:-

#exercise 2
num=input('Enter a number :')

#converting entry to integer
convertedNum=int(num)
if(convertedNum>99):
    print("hundreds")

SCREENSHOT OF THE CODE AND SAMPLE OUTPUT:-

EXERCISE 3:-

#exercise 3
num=input('Enter a number :')

#converting entry to integer
convertedNum=int(num)
if(convertedNum<0):
    print("negative")

SCREENSHOT OF THE CODE AND SAMPLE OUTPUT:-

EXERCISE 4:-

#exercise 4
num=input('Enter a number :')

#converting entry to integer
convertedNum=int(num)
if(convertedNum<0):
    print("negative")
else:
    print("positive")

SCREENSHOT OF THE CODE AND SAMPLE OUTPUT:-

EXERCISE 5:-

#exercise 5
num=input('Enter a number :')

#converting entry to integer
convertedNum=int(num)
if(convertedNum>99):
    print("hundreds")
else:
    print("low number")

SCREENSHOT OF THE CODE AND SAMPLE OUTPUT:-

EXERCISE 6:-

#exercise 6
num=input('Enter a number :')

#converting entry to integer
convertedNum=int(num)
if(convertedNum==2001):
    print("Twin Towers")
elif(convertedNum==2008):
    print("Great Recession")
elif(convertedNum==2017):
    print("Hurricane Maria")
else:
    print("No Disasters")

SCREENSHOT OF THE CODE AND SAMPLE OUTPUT:-

EXERCISE 7:-

#exercise 7
num=input('Enter a number :')

#converting entry to integer
convertedNum=int(num)
if(convertedNum==2001):
    print(num+" : Twin Towers")
elif(convertedNum==2008):
    print(num+" :Great Recession")
elif(convertedNum==2017):
    print(num+" :Hurricane Maria")
else:
    print("No Disasters")

SCREENSHOT OF THE CODE AND SAMPLE OUTPUT:-

HAPPY LEARNING


Related Solutions

4.10 Branching Practice 2 - Python Exercise #Write the code for the following #Exercise 1 #Ask...
4.10 Branching Practice 2 - Python Exercise #Write the code for the following #Exercise 1 #Ask the user to input a name using an input statement (no prompt) and assign it to a variable #Condition: user input is equal to 'Joseph' #Action: display the user input on screen #Exercise 2 #Ask the user to input his/her first name using an input statement (no prompt) and assign it to a variable #Condition: user input is equal to 'Joseph' #Action: display the...
Python Practice Sample:   Write code to replace every occurrence of THE or the with ### and...
Python Practice Sample:   Write code to replace every occurrence of THE or the with ### and every word ending with the letter s to end with a $. Print the resulting text four words per line (and any remaining words from each paragraph on the last one of each paragraph) "The modern business world goes way beyond the balance sheet. Whether your passion is finance or fashion, economics or the environment, you need an education built for business. At Bentley,...
please answer this in a simple python code 1. Write a Python program to construct the...
please answer this in a simple python code 1. Write a Python program to construct the following pattern (with alphabets in the reverse order). It will print the following if input is 5 that is, print z one time, y two times … v five times. The maximum value of n is 26. z yy xxx wwww vvvvvv
Write code in Python that does the following : An anagram is when the order of...
Write code in Python that does the following : An anagram is when the order of a word can be changed to create a new word (evil, live, and vile for example). Using the dictionary provided, find all of the anagram groups. Which words contain the most anagrams? How large is this group? Here is another example: Alert, alter, and later have 3 in their group. Use the provided dict.txt as your word list, solution must also finish in less...
Please write in Python code Write a program that stores the following data in a tuple:...
Please write in Python code Write a program that stores the following data in a tuple: 54,76,32,14,29,12,64,97,50,86,43,12 The program needs to display a menu to the user, with the following 4 options: 1 – Display minimum 2 – Display maximum 3 – Display total 4 – Display average 5 – Quit Make your program loop back to this menu until the user chooses option 5. Write code for all 4 other menu choices
Using python as the coding language please write the code for the following problem. Write a...
Using python as the coding language please write the code for the following problem. Write a function called provenance that takes two string arguments and returns another string depending on the values of the arguments according to the table below. This function is based on the geologic practice of determining the distance of a sedimentary rock from the source of its component grains by grain size and smoothness. First Argument Value Second Argument Value Return Value "coarse" "rounded" "intermediate" "coarse"...
In python please write the following code the problem. Write a function called play_round that simulates...
In python please write the following code the problem. Write a function called play_round that simulates two people drawing cards and comparing their values. High card wins. In the case of a tie, draw more cards. Repeat until someone wins the round. The function has two parameters: the name of player 1 and the name of player 2. It returns a string with format '<winning player name> wins!'. For instance, if the winning player is named Rocket, return 'Rocket wins!'.
Please write in beginner level PYTHON code! Your job is to write a Python program that...
Please write in beginner level PYTHON code! Your job is to write a Python program that asks the user to make one of two choices: destruct or construct. - If the user chooses to destruct, prompt them for an alternade, and then output the 2 words from that alternade. - If the user chooses construct, prompt them for 2 words, and then output the alternade that would have produced those words. - You must enforce that the users enter real...
CODE IN PYTHON 1. Write a program that asks the user for the number of slices...
CODE IN PYTHON 1. Write a program that asks the user for the number of slices of pizza they want to order and displays the total number of dollar bills they owe given pizza costs 3 dollars a slice.  Note: You may print the value an integer value. 2. Assume that y, a and b have already been defined, display the value of x: x =   ya+b    3. The variable start_tees refers to the number of UD T-shirts at the start...
Python code Assignment Overview In this assignment you will practice with conditionals and loops (for). This...
Python code Assignment Overview In this assignment you will practice with conditionals and loops (for). This assignment will give you experience on the use of the while loop and the for loop. You will use both selection (if) and repetition (while, for) in this assignment. Write a program that calculates the balance of a savings account at the end of a period of time. It should ask the user for the annual interest rate, the starting balance, and the number...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT