Question

1) In Python Use a while loop to ask the user to enter a series of...

1) In Python Use a while loop to ask the user to enter a series of alphabets. The loop terminates when the user presses enter. Once the loop terminates, display the number of vowels and consonants entered by the user.

Hint: keep a running count of the number of characters entered by the user. Keep a running count of the number of vowels.

Total number of consonants = total number of characters - total number of vowels.

Assume that the user will only ever enter alphabets.

2)in python Ask the user to enter a number n'. Calculate the sum of all the numbers from 1 to n. Display the average sum of the numbers.

Homework Answers

Answer #1

Answer 1:

Program 1:

#Python 3 program:
#take input
alphabet = ''
character =' '

print("Enter alphabet: \n")
#The loop terminates when the user presses enter. 
while character != "" : #if user press enter key then null string is captured and our loop terminates
    character = input()
    alphabet = alphabet+character

vowelstr = [each for each in alphabet if each in "AaEeIiOoUu"] 
print("No of Vowels = ",len(vowelstr))

#total number of consonants = total number of characters - total number of vowels.
print("\nNo of Consonants = ", len(alphabet)-len(vowelstr))

Program Code Screenshot:

Program Output Screenshot:

Answer 2:

Program 2:

#take input
n = int(input("Enter the number \'n\'\n"))
sum =0
#this will include numbers from 1 to n as range function generate numbers till n-1 so keeo n+1 below
for i in range(1,n+1):
    sum = sum+i

print("Sum : ", sum)
print("\nAverage : ", sum/n)

Program Screenshot:

Output Screenshot:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a python code that will ask the user to enter an integer number n. Construct...
Write a python code that will ask the user to enter an integer number n. Construct a recursive function that prints numbers 1 to n in the form “11223344..nn”.
In pseudo code (or python) create a loop that will ask the use to enter and...
In pseudo code (or python) create a loop that will ask the use to enter and then add five zip codes to a one-dimensional array called zip code and then read and display that zip code array to the screen.
Please use Python 3 4). Write a program that asks the user to enter 10 numbers....
Please use Python 3 4). Write a program that asks the user to enter 10 numbers. The program should store the numbers in a list and then display the following data: • The lowest number in the list • The highest number in the list •The total of the numbers in the list • The average of the numbers in the list   Sample input & output: (Prompt) Enter Number 1: (User enter) 4 (Prompt) Enter Number 2: (User enter) 7...
Write the C++ language statements to ask a user to enter a number within the range...
Write the C++ language statements to ask a user to enter a number within the range of 0 to 100 (0 and 100 are valid inputs). When the value is not valid, you should prompt the user to enter another value. (The user may enter many invalid numbers, so you must use loop). Only after the user enters a valid number should you display the message “Good” and the value of the number.
Write a PYTHON program that displays a weekly payroll report. A loop in the program should...
Write a PYTHON program that displays a weekly payroll report. A loop in the program should ask the user for the employee number, gross pay, state tax, federal tax, and FICA withholdings. The loop will terminate when 0 is entered for the employee number. After the data is entered, the program should display totals for gross pay, state tax, federal tax, FICA withholdings, and net pay. Input Validation: ▪ Do not accept negative numbers for any of the items entered....
8.39 Lab 8d: Even Entry Loop This program will ask the user to enter an even...
8.39 Lab 8d: Even Entry Loop This program will ask the user to enter an even number and continue to do so until they enter the given QUIT condition. The prompt for the user to enter a number is written as follows: "Enter an even number or [QUIT] to quit:" The quitting condition in this case will be the number 999. If the number they entered was an even number, output the message "Good job!" Otherwise, output the message "[number]...
Write a Python program which calculates the average of the numbers entered by the user through...
Write a Python program which calculates the average of the numbers entered by the user through the keyboard. Use an interactive loop and ask the user at each iteration if he/she wants to enter more numbers. At the end dispay the average on the screen. Using built-in library functions for finding average is not allowed. Sample output of the program: Enter a number > 23 More numbers (yes or no)? y Enter a number > 4 Do you have more...
design a program that prompts the user to enter a positive integer number and reads the...
design a program that prompts the user to enter a positive integer number and reads the user’s input. If the user input is not a positive number, the program should prompt them repeatedly until they enter a valid input. Once a valid input is received ,the program uses a loop to calculate the sum of the digits of the user’s input and displays the sum. For example, if the user enters the number 94311, the program should print the sum...
im trying to make a program that will use a while loop to repeatedly ask a...
im trying to make a program that will use a while loop to repeatedly ask a user for a test score. Use a counter to exit the loop when the user has entered 10 test scores. The loop is to figure out the total of all the scores and the highest score. it must use a while loop please explain problems in code the bottom code is my work done but does not work. #include <iostream> using namespace std; int...
Python code only! (Do not include breaks or continue functions) Write a program that asks the...
Python code only! (Do not include breaks or continue functions) Write a program that asks the user to enter the amount that they budgeted for the month. A loop should then prompt the user to enter their expenses, one at a time and to enter 0 to quit. When the loop finishes, the program should display the the amount of budget left. (a negative number indicates the user is over budget and a positive number indicates the user is under...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT