Exercise 2: [10 marks]Write a Python program to find and print the sum of 5positive integergiven by user(save your code asa program named sumOfInputs.py
Answer:
#initialize sum with zero
sum=0
#Ask user input in loop for five times
for i in range(0,5):
#take user input in variable named number
number = input("Enter Number: ")
#add new number in sum
sum+=number
#take avg by dividing sum with total inputs
avg=sum/5.0
#print sum
print("Sum is: ")
print(sum)
#print Average
print ("Average is: ")
print(avg)
OUTPUT:
Upvote the answer(as much needed for me) if it helps else let me know your doubts. Thank you!!
Exercise 2: [10 marks]Write a Python program to find and print the sum of 5positive integergiven...
Exercise 9.2 Write a Python program that collects from the user a single integer. Have the program print “EVEN” if the integer is divisible by 2, and “ODD” if the integer is not divisible by two. [Use the % operator to compute the two’s modulus (remainder of division by two)] Exercise 9.3 Write a Python program that collects from the user two integers. Have the program print “Yes” if the two integers are BOTH greater than 10. Do nothing if...
1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...
Write a PYTHON program that asks the user for the name of the file. The program should write the contents of this input file to an output file. In the output file, each line should be preceded with a line number followed by a colon. The output file will have the same name as the input filename, preceded by “ln” (for linenumbers). Be sure to use Try/except to catch all exceptions. For example, when prompted, if the user specifies “sampleprogram.py”...
#Starting Out With Python, 4th Edition #Chapter 7 #Exercise 6 #in a program, write a function named roll that #accepts an integer argument number_of_throws. The #function should generate and return a sorted #list of number_of_throws random numbers between #1 and 6. The program should prompt the user to #enter a positive integer that is sent to the function, #and then print the returned list. How would you do this?
C++ code blocks Exercise#2: Quiz marks Write a program that generates quiz marks at random, between O and 10 inclusive, for a number (less than 50) of Your program should display the marks, class average, and how many students score students decided by the user. above class average. Sample input/output: nter class size: 15 uiz marks: 8 9 9 1 7 5 5 10 1 07 7 5 8 6 e class average is: 5.87 students scored above average
write in python Create a program that will ask the user for a list of integers, all on one line separated by a slash. construct a list named "adj_numbers" which contains the users input numbers after subtracting 2 from each number. then print the resulting list. the input statement and print statement are given to you in the starting code. a sample run of the program is as follows: Enter a list of integers, separated by slashes: 7/3/6/8 resulting list:...
Please use python to write the simple program. Exercise 2 - Summation Write a program to accept integer inputs until the user inputs a non-integer. Then, the program prints the summation of the inputted numbers. Hint: Use the function input() to get the user input. Use a variable total for calculating the summation. Need to use while loop for the repeated inputs. Use if statement with isdigit() function to check whether the user input is an integer or not. if...
I want solve it Question (4): (5 marks) Write a Python program to print all even numbers in given list. Example: Input: list_1 = (2, 4, 5, 7, 13, 44, 45] Output: [2, 4,44]
Write a Python program to print a timetable. E.g. printTimesTable(n), 1<n<10 Or you can make your program be interactive with user by S. Asking user to input their number n. Your program will generate a table such as the following: 1 2 3456789 24 6 8 10 12 14 16 18 3 6 91215 18 21 24 27 4 812 16 20 24 28 32 36 5 10 15 20 25 30 35 40 45 6 12 18 24 30...
Python assignment: Write a program that asks for the user's age. Based on their response print "You can vote" (18 years old or older) or "You can't vote" and also whether or not he/she is a senior citizen (over 64). If senior citizen print "You're a Senior Citizen...you deserve two votes"! Use the Idle editor and don't forget the .py extension. Good luck. Your python program will be graded on the following: Execution of the program gives the correct...