Question

In: Computer Science

(PYTHON) prompt the user to enter a single-digit num and print that num as follow: 1)...

(PYTHON)

prompt the user to enter a single-digit num and print that num as follow:

1) use loops

2) print num in words. Example: 5 is 'five'

3) the number of spaces that go back and forth should equal the num

if the user inputs 5, the program prints:

five

. . . . .five

five

. . . . . five

five

and 2 would be:

two

. .two

(the periods(.) are only for demonstration purposes. Don't include it in the actual output).

Solutions

Expert Solution

program with explanation (Python 3.7)

# python dictionary used to store key: value pair.
# Dictionaries are optimized to retrieve values when the key is known.
num2words = {1: 'One', 2: 'Two', 3: 'Three', 4: 'Four', 5: 'Five', 6: 'Six', 7: 'Seven', 8: 'Eight', 9: 'Nine'}

# function definition part
def number(Number):
  
# if condition: used to check number between 0 and 10
if (Number >= 1) and (Number <=9):
  
# Using the key retrieves the value from the dictionary
value= num2words[Number]
  
# Loop part : printing the number in its number of times
for x in range(Number):
print(value)
else:
# else part of the loop
print("Number Out Of Range")
  
# calls main() for continue this problem
main()

# main part part of the program
# when program runs it start from here
def main():
  
# Takes input from the user
num = eval(input("Please enter a number between 0 and 10: "))
  
# function calling part and pass value num
number(num)
  
# calling main() to start program
main()

code only(Python 3.7)

num2words = {1: 'One', 2: 'Two', 3: 'Three', 4: 'Four', 5: 'Five', 6: 'Six', 7: 'Seven', 8: 'Eight', 9: 'Nine'}
def number(Number):
if (Number >= 1) and (Number <=9):
value= num2words[Number]
for x in range(Number):
print(value)
else:
print("Number Out Of Range")
main()
def main():
num = eval(input("Please enter a number between 0 and 10: "))
number(num)
main()

output


Related Solutions

*******************In Python please******************* (1) Prompt the user to enter a string of their choosing. Store the...
*******************In Python please******************* (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes; more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be more shuttle flights and more...
Prompt the user to enter an integer Then, prompt the user to enter a positive integer...
Prompt the user to enter an integer Then, prompt the user to enter a positive integer n2. Print out all the numbers that are entered after the last occurrence of n1 and whether each one is even or odd If n1 does not occur or there are no values after the last occurrence of n1, print out the message as indicated in the sample runs below. Sample: Enter n1: -2 Enter n2: 7 Enter 7 values: -2 3 3 -2...
using python/IDLE (1) Prompt the user to enter a string of their choosing. Store the text...
using python/IDLE (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes; more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be more shuttle flights and more...
8.30 LAB*: Program: Authoring assistant. PYTHON PLEASE!! (1) Prompt the user to enter a string of...
8.30 LAB*: Program: Authoring assistant. PYTHON PLEASE!! (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes; more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be...
Write a C++ program that asks the user to enter a series of single-digit numbers with...
Write a C++ program that asks the user to enter a series of single-digit numbers with nothing separating them. Read the input as a C-string or a string object. The program should display the sum of all the single-digit numbers in the string. For example, if the user enters 2514, the program should display 12, which is the sum of 2, 5, 1, and 4. The program should also display the highest and lowest digits in the string. It is...
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)
Answer using Jupyter Python #Prompt the user to enter a passing grade and store the value...
Answer using Jupyter Python #Prompt the user to enter a passing grade and store the value from #the input() into a variable. #Refer to the variable in problem 2 to complete the following: #Use the if statement to evaluate the only the first element in the #grades list using index notation. #If the grade is passing, display PASSED, otherwise display FAILED. """Problem 1d""" #Use the for statement to iterate on each element in the #grades list (from problem 1a) and...
Answer using Jupyter Python #Prompt the user to enter a passing grade and store the value...
Answer using Jupyter Python #Prompt the user to enter a passing grade and store the value from #the input() into a variable. #Refer to the variable in problem 2 to complete the following: #Use the if statement to evaluate the only the first element in the #grades list using index notation. #If the grade is passing, display PASSED, otherwise display FAILED. """Problem 1d""" #Use the for statement to iterate on each element in the #grades list (from problem 1a) and...
Python Code: Write a program to prompt the user to enter a first name, last name,...
Python Code: Write a program to prompt the user to enter a first name, last name, student ID, number of hours completed and GPA for 5 students. Use a loop to accept the data listed below. Save the records in a text file. Write a second program that reads the records from your new text file, then determines if the student qualifies for Dean’s list or probation. Display the records read from the file on screen with appropriate headings above...
(PYTHON) Lottery program. The program randomly generates a two-digit number, prompts the user to enter a...
(PYTHON) Lottery program. The program randomly generates a two-digit number, prompts the user to enter a single two- digit number, and determines whether the user wins according to the following rules. Write a loop to let the user play as many times as the user wanted. Use a sentinel or flag to quit out of the loop. 1.if the user’s input matches the lottery In the exact order, the award is $10,000. 2.if all the digits in the user’s input...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT