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...
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...
Write a Python program stored in a file q3.py that: Gets single-digit numbers from the user...
Write a Python program stored in a file q3.py that: Gets single-digit numbers from the user on one line (digits are separated by white space) and adds them to a list. The first digit and the last digit should not be a zero. If the user provides an invalid entry, the program should prompt for a new value. Converts every entry in the list to an integer and prints the list. The digits in the list represent a non-negative integer....
Create in Java a program that will prompt the user to enter aweight for a...
Create in Java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates both bolus and infusion rates based on weight of patient in an interactive GUI application, label it AMI Calculator. The patients weight will be the only entry from the user. Use 3999 as a standard for calculating BOLUS: To calculate the BOLUS you will multiply 60 times the weight of the patient for a total number. IF the...
Create in java a program that will prompt the user to enter a weight for a...
Create in java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates infusion rates based on weight of patient in an interactive GUI application, label it HEPCALC. The patients’ weight will be the only entry from the user. To calculate the infusion rate you will multiply 12 times the weight divided by 50 for a total number. The end result will need to round up or down the whole number....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT