Question

In: Computer Science

ALL IN PYTHON PLEASE Problem 1: Accept one integer from the user and store that information...

ALL IN PYTHON PLEASE

Problem 1: Accept one integer from the user and store that information in a variable called endNo. Use an IF structure to check that endNois a positive number. If endNo is negative, print an error message and stop. If it is positive, use a loop (for or while) to generate odd numbers from 1 to endNo. Calculate the sum of these numbers using an accumulator.

Rubric:

Data input and data type conversions: 2.5 pts
Use of IF structure to verify that endNo is positive: 2.5 pts
Use of loop to generate numbers from a (inclusive) to b (not inclusive): 5 pts
Use of an accumulator (note: print the cumulative sum only once): 5 pts

Problem 2:

Modify problem 1 and allow the user to specify the (a) starting value for the loop, (b) stopping value for the loop, and (c) the step function. Please note that the stopping value must be included in the calculation of your running total. Example of the desired solution:

Enter starting value: 5

Enter stopping value: 15

Enter step value: 5

30


In the above example, the result (30) is the sum of 5 + 10 + 15. Note that both the starting value and ending value are included in the running total. The step value determines the series.

Rubric:

Modification of the loop function: 5 pts

Problem 3:

Define a VALUE-RETURNING function that accepts one parameter - an integer number. The function, which must be a value-returning function, returns 1 if the number is even or 0 if the number is odd. In the “main” function (i.e. def main()), capture the return value and print an appropriate message on screen (i.e. number is even or odd).

Rubric:

Correctly defined a value-returning function: 5 pts

Correctly capture and use return value from a value-returning function: 5 pts

Sample Output:

Enter n: 4
Even

Problem 4

Write a program to compute the area of a circle some 'n' times. You must accept n and r from the user. Area is calculated using (22/7.0)*r*r - where r is the radius. Implement using value-returning functions. Hint: create a function to calculate area taking r as a parameter. In the main() function, ask for n and create a loop where you input r and invoke the area function n times.

Rubric:

Correct use of a loop to perform n calculations for the user: 5 pts
Correct use of value-returning functions inside a loop structure: 10 pts

Sample Output:

Enter n: 3

Enter r: 34

Area is: 3633.14285714

Enter r: 23

Area is: 1662.57142857

Enter r: 43

Area is: 5811.1428571

Solutions

Expert Solution

#Please ask 1 question at a time, i have answered 1st 2

#1
endNo = int(input('Enter an integer: '))
if endNo<=0:
print('Error: integer entered must be positive!!!')
else:
total=0
n=1
while n<=endNo:
total+=n
n+=2
print(total)
  
#2
start=int(input('Enter starting value: '))
end=int(input('Enter stopping value: '))
step=int(input('Enter step value: '))
total=0
num=start
while num<=end:
total+=num
num+=step
print(total)


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...
Write a program that accept an integer input from the user and display the least number...
Write a program that accept an integer input from the user and display the least number of combinations of 500s, 100s, 50s, 20s, 10s, 5s, and 1s. Test your solution using this samples] a. Input: 250 Output: 1x200s, 1x50s b. Input: 1127 Output: 5x200s, 1x100s, 1x20s, 1x5s, 2x1s c. Input: 1127 Output: 5x200s, 1x100s, 1x20s, 1x5s, 2x1s d. Input: 19 Output: 1x10s, 1x5s, 4x1s ​[Hints] o Use division to determine the number of occurrence of each element (i.e. 200, 100)...
python programming. Write a program that prompts the user to enter an integer from 0 to...
python programming. Write a program that prompts the user to enter an integer from 0 to 9. The program will check if the input is a positive integer. It displays the correct answer and shows the guess is correct or not. The demos are shown as following.(Hint:1. Use a random math function 2. Use str.isdigit() to check the input)
Write a Python function that will do the following:1. Ask the user to input an integer...
Write a Python function that will do the following:1. Ask the user to input an integer which will be appended to a list that was originally empty. This will be done 5 times, meaning that when the input is complete, the list will have five elements (all integers).2. Determine whether each element is an even number or an odd number3. Return a list of five-string elements "odd" and "even" that map the indexes of the elements of the input list,...
Problem 1 Write a program that prompts the user to enter an integer It then tells...
Problem 1 Write a program that prompts the user to enter an integer It then tells the user if the integers is a multiple of 2, 3, 5, 7 or none of the above. Program language is C Ex. Enter an integer 12 You entered 12 The number you entered is a multiple of 2 ----------------------------------------------- Enter an integer 11 You entered 11 The number you entered is not a multiple of 2, 3, 5, or 7
ALL IN PYTHON PLEASE Problem 3: Define a VALUE-RETURNING function that accepts one parameter - an...
ALL IN PYTHON PLEASE Problem 3: Define a VALUE-RETURNING function that accepts one parameter - an integer number. The function, which must be a value-returning function, returns 1 if the number is even or 0 if the number is odd. In the “main” function (i.e. def main()), capture the return value and print an appropriate message on screen (i.e. number is even or odd). Rubric: Correctly defined a value-returning function: 5 pts Correctly capture and use return value from a...
On Python a) Use format() method to print an integer value entered by the user and...
On Python a) Use format() method to print an integer value entered by the user and its cube root with two decimal places. b) Print the same values as part (a) using format() function with keyword arguments and labels number and cubeRoot as in: format(number=n,cubeRoot=cr) c) Switch the order of keyword arguments and show that this has no effect on the output.
. Create a Python function that asks the user for a number (integer). The function should...
. Create a Python function that asks the user for a number (integer). The function should then tell the user how many hundreds can go into the number, and how much is left over. Hint: the % operator calculates the remainder of a division. For example, 10 % 3 gives a result 1. Hint2: Deal with the positive and negative values in separate parts of an if-else structure. Get the calculation work for positive values first. For negative values, make...
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...
Write a program that prompts a user for an integer from 1 to 99 and prints...
Write a program that prompts a user for an integer from 1 to 99 and prints it as an amount in words. The program will loop in case the user wants to input an additional number. If the user enters -99, the program will exit. Example: Input: 89 Output: Eighty nine Input: 45 Output: Fourty five Input: -99 Output: Have a nice day. <program exits> For this project, you are to: 1) You should validate any data coming from the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT