Question

(Python Programming) Write a program that prompts a user for a positive integer and then uses...

(Python Programming)

Write a program that prompts a user for a positive integer and then uses a loop to calculate and display the sum of specific fractions as follows:

Let's say the user enters 5, then your program will compute: 1/5 + 2/4 + 3/3 + 4/2 + 5/1 which is 8.7.

Homework Answers

Answer #1

CODE -

# Taking a number from user as input
num = int(input("Enter a number: "))
# Initializing the sum of specific fractions to 0
sum_frac = 0
# Calculating the sum of specific fractions using for loop
for i in range(1, num+1):
sum_frac += (i / (num-i+1))
# Displaying the sum of specific fractions.
print(sum_frac)

SCREENSHOT -

If you have any doubt regarding the solution, then do comment.
Do upvote.

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 program that prompts the user to enter an integer number between 1 and 999....
Write a program that prompts the user to enter an integer number between 1 and 999. The program displays the sum of all digits in the integer if the input is valid; otherwise, it displays a message indicating that the integer is not between 1 and 999 and hence, is invalid. Name the program file Q1.cpp Example: if the user enters 12, sum of digits is 3. If the user enters 122, sum of digits is 5.
Write a program that asks the user of a positive integer value. The program should use...
Write a program that asks the user of a positive integer value. The program should use a loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1,2,3,4,…,50. using namespace std;
Collapse Write a program that prompts the user to input a positive integer. It should then...
Collapse Write a program that prompts the user to input a positive integer. It should then output a message indicating whether the number is a prime number. (Note: An even number is prime if it is 2. An odd integer is prime if it is not divisible by any odd integer less than or equal to the square root of the number.) Turn in: Your source code for with The name of your program as a comment at the top...
The Java program should sum the odd integers from 1 to the integer that the user...
The Java program should sum the odd integers from 1 to the integer that the user enters. For example, if the user enters 30, the program should sum the odd integers from 1 to 30.   Print "Please enter a positive nonzero integer." Declare a Scanner and obtain an integer from the user.   Use a Do...while statement and calculate the sum Use the integer that the obtained from the previous step for the loop-continuation condition. Display the sum Print the sum...
Write a python program that does the following: Prompts the user for three numbers in one...
Write a python program that does the following: Prompts the user for three numbers in one request. Be sure to specify the “delimiter” by which a user enters those three numbers. Divides the first number by the second number and add that result to the third number. Prints output that shows in one line the formula applied and the result of the calculation. Validate input by: •    Checking the user entered 3 values •    Appropriately checking for the following errors:...
Be able to write Python programming of a factorial of an integer (given input parameters, output...
Be able to write Python programming of a factorial of an integer (given input parameters, output characteristics and expected output behavior, do not use internal python functions for factorials), recall for example that: 5! = 5 ∗ 4 ∗ 3 ∗ 2 ∗ 1 = 120 and to continue asking unless user says to stop NOT USING FACTORIAL FUNCTION
Question: Squares. Write a program class named SquareDisplay that asks the user for a positive integer...
Question: Squares. Write a program class named SquareDisplay that asks the user for a positive integer no greater than 15. The program should then display a square on the screen using the character ‘X’. The number entered by the user will be the length of each side of the square. For example, if the user enters 5, the program should display the following:       XXXXX       XXXXX       XXXXX       XXXXX       XXXXX INPUT and PROMPTS. The program prompts for an integer as follows: "Enter...
(8 marks) Write a program to ask user to input an integer and display the special...
Write a program to ask user to input an integer and display the special pattern accordingly. REQUIREMENTS The user input is always correct (input verification is not required). Your code must use loop statements (for, while or do-while). Your program should use only the following 3 output statements, one of EACH of the followings: System.out.print("-"); // print # System.out.print("+"); // print + System.out.println(); // print a newline Your code must work exactly like the following example (the text in bold...
Please use Python programming language to write a client program and a server program, so that...
Please use Python programming language to write a client program and a server program, so that these two programs communicate through a TCP connection based on the following scenario: Both of the client program and the server program are running on the same localhost. The client program prompts the user to enter the radius of a circle and pass it to the server program. The server program computes the area of this circle and passes it to the client program....
Write a program that prompts the user for a number from 1 to 200 until 113...
Write a program that prompts the user for a number from 1 to 200 until 113 is encountered. Not including the 113, calculate the average. Do this in python. DO NOT USE LISTS!
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT