Question

In: Computer Science

Python age = input(‘How old are you? ’) if age >= 14 print(‘You may go on...

Python

  1. age = input(‘How old are you? ’) if age >= 14

    print(‘You may go on the rollercoaster’)

    Read carefully - What will the program output if the user types ‘15’?

2. Concisely explain the difference between ‘while’ and ‘for’ ______________________________________________

3.The __________statement terminates the loop containing it. Control of the program flows to the statement immediately after the body of the loop.

4.The ____________ statement is used to skip the rest of the code inside a loop for the current iteration only. Loop does not terminate but executes the next iteration of the loop.

______________________________________________

Solutions

Expert Solution

Question 1.

Output:

No output. It will throw an error that " >= not supported between instances of str and int"

Explanation:

In the input we are taking input as a string. So 15 will be read as a string not integer. And in if statement we are comparing age which is string with 14 which is integer so there will be an error hence program will get terminated stating the above error.

To read a input as an integer.

age=int(input ("How old are you?")

Question 2:

While loop for loop
The while statement loops untill a condition is false.

Iterate through a loop with definite range or collections

Example: for i in range(5):

While loop is used when the number of iteration are not exactly known for loop is used when we exactly know the number of iterations.

Question 3:

The BREAK statement terminates the loop containing it. Control of the program flows to the statement immediately after the body of the loop.

Question 4:

The CONTINUE statement is used to skip the rest of the code inside a loop for the current iteration only. Loop doesn't terminate but executeas the next iteration of the loop.


Related Solutions

Python #For question 1 and 2 you may not use ''' ''' Question 1 Print the...
Python #For question 1 and 2 you may not use ''' ''' Question 1 Print the messages below without using variables. Output must be 2 lines identical to below: What is the snake's favorite language? "I love Python", said the snake. Question 2 Write a python statements to match the 5 lines of output below. Use a single print statement to produce the list of 4 languages The 3 most popular programming languages of 2020 are: 1.         Python 2.         Javascript 3.         Java 4.         C#...
Write a java program that will take a line of input and go through and print...
Write a java program that will take a line of input and go through and print out that line again with all the word numbers swapped with their corresponding numeric representations (only deal with numbers from one to nine). Sample runs might look like this: Please enter a line of input to process: My four Grandparents had five grandchildren My 4 grandparents had 5 grandchildren without array and methods.
Python Write a program that will analyse the string input and print “accept” or “reject” based...
Python Write a program that will analyse the string input and print “accept” or “reject” based on the pattern given Accept if it fulfils the following conditions -String length 9 -3 small alphabet (3 lowercase letter) -3 digits -3 big alphabet (3 uppercase letters) -1st alphabet should be a capital -Last alphabet should be a number -Two consecutive alphabets can't be small Reject if any of the conditions is absent So i want it to accept or reject my input,...
Write a Python program which prompts the user to input a string. Then, print the string...
Write a Python program which prompts the user to input a string. Then, print the string in reverse to the terminal Sample output Please enter a word: "zeus" The reverse of zeus is suez Hint: There are several ways to accomplish this. Recall that a string is an itterable object and therefore can be used with a for loop
Use Python: Develop neurons and print truth table of the following 2-input logic gates: AND, OR,...
Use Python: Develop neurons and print truth table of the following 2-input logic gates: AND, OR, NAND, NOR, XOR, XNOR and 1-input NOT gate (Notice: use Markdown to explain how you developed a neuron, and to insert images showing the truth table of logic gates before coding)
Computer Organization Input your age (my age is 20 years old) and display what your age...
Computer Organization Input your age (my age is 20 years old) and display what your age would be next year(21 year) Submit screen shots from Marie. I think this should display on Java programming Language
Python #Use an input statement to ask the user for his/her age (no prompt) and assign...
Python #Use an input statement to ask the user for his/her age (no prompt) and assign the user entry to a variable #Convert the user input to an integer and assign to a variable #Write if-elif-else statements with the following conditions and actions #Important: For each Action below, use the same variable name for the rating in all the if, elif, and else statements #Condition: user input less than or equal to 9 Action: assign the letter G as a...
using python 3 1. Two-line input: print a prompt (e.g Enter your first name) and then...
using python 3 1. Two-line input: print a prompt (e.g Enter your first name) and then assign the input to a variable print ("Enter your first name")# the word prompt is the message the user should see firstName = input() print (firstName)
In python can you fix the error in the line where it says message = input("Input...
In python can you fix the error in the line where it says message = input("Input a lowercase sentence: ") this is the error message I get after running the program and inputing a lowercase sentence Input a lowercase sentence:hello hi MM§MTraceback (most recent call last): MM§M File "client.py", line 14, in <module> MM§M message = input("Input a lowercase sentence:") MM§M File "<string>", line 1 MM§M hello hi MM§M ^ MM§MSyntaxError: unexpected EOF while parsing from socket import * #...
Sofia is 45 years old. She has 3 children, Meg age 12, Jo age 14 and...
Sofia is 45 years old. She has 3 children, Meg age 12, Jo age 14 and Amy age 15. However, she is already planning for retirement. She plans on retiring in 15 years when she will be 60 years old. Sofia believes she will live until she is 100. In order to live comfortably, she thinks she will need to withdraw $12,000 every month during retirement. These weekly withdrawals will be made at the beginning of each month during retirement....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT