Question

Write a code using loop and flag function in python jupitior notebook: Ask the user for...

Write a code using loop and flag function in python jupitior notebook:

Ask the user for the number of items they bought. Also ask the price of each item they bought and quantity purchased. Display the total amount they owe.

Ask the user for a number n. Calculate 1+2+3+….+n.

Ask the user for a number n. Calculate 1*2*3*…*n.

Ask the user for number of rows (r) and columns (c). Print * for r rows and c columns.

Ask the user for the number of rows (r). Print * for r rows with each row having as many *s as the row’s number. For example, if the user enters 5, your output should look like:

*

**

***

****

*****

Modify the code you wrote for the problem above to get the following:

Enter number of rows: 5

*

**

***

****

*****

****

***

**

*

Write a for loop that displays the following set of numbers: 0, 10, 20, 30, 40, 50 . . . 1000

Ask the user to enter 10 numbers and keep/display a running total of the numbers entered.

Running on a particular treadmill you burn 4.2 calories per minute. Write a program that uses a loop to display the number of calories burned after 10, 15, 20, 25, and 30 minutes.

Collatz Sequence:

Let’s look at a simple sequence that has fascinated and foxed mathematicians for many years.

The “computational rule” for creating the sequence is to start from some given n, and to generate the next term of the sequence from n, either by halving n, (whenever n is even), or else by multiplying it by three and adding 1 (that is, 3n+1). The sequence terminates when n reaches 1.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note : According to HomeworkLib policy answered only first 4 questions

Program 1 :

n=int(input("Enter number of items: "))
tsum=0
for i in range(n):
print("Enter item ",i+1,"amount");
iamount=int(input())
tsum=tsum+iamount;
print("Total amount for ",n," item is ",tsum )

screen shot of the program :

main.py 1 n=int(input(Enter number of items: )), 2 tsum=0 3- for i in range(n): 4 print(Enter item ,i+1, amount); 5 iam

Program 2:

n=int(input("Enter a number : "))
s=0
for i in range(n):
s=s+i+1;
print("sum of the first ",n,"natural numbers is:",s)

screen shot of the program :

main.py 1 n=int(input(Enter a number : )) 2 s=0 3 for i in range(n): 4 s=s+i+1; 5 print(sum of the first, n, natural num

Program 3:

n=int(input("Enter a number : "))
s=1
for i in range(n):
s=s*(i+1);
print("Multiplication of the first ",n,"natural numbers is:",s)

Screen shot of the program :

RUN Devy s p Side Save u Dedully main.py 1 n=int(input(Enter a number : )) 2 s=1 3- for i in range(n): s=s*(i+1); 5 print(

Program 4:

r=int(input("Enter number of rows: "))
c=int(input("Enter number of columns: "))
for i in range(r):
for j in range(c):
print("*",end=" ")
print()

Screen shot of the program :

Run Debug Stop Share Save main.py 1 ruint(input(Enter number of rows: )) 2 Cuint(input(Enter number of columns: )), 3- fo

Add a comment
Know the answer?
Add Answer to:
Write a code using loop and flag function in python jupitior notebook: Ask the user for...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write Java code that does the following Ask the user to enter a file name. Ask...

    Write Java code that does the following Ask the user to enter a file name. Ask the user for two integers as the lower bound and the upper bound. Use a loop to write all the odd numbers between the lower bound and the upper bound (inclusive) to the file, and then close the file. Use either while loop, do while loop, or for loop to complete the program. PrintWriter class is used. The file is closed before the program...

  • java programming!!! Write the code fragment that will do the following: • Ask the user how...

    java programming!!! Write the code fragment that will do the following: • Ask the user how many numbers they want to enter • Declare and instantiate an array of doubles with as many elements as the number entered by the user • Write one 'for' loop to fill the array with data from the user • Write a second 'for' loop to calculate the sum of all of the numbers in the array • Print the calculated sum Note: Write...

  • Please answere using python language codes. Write a program to print out Collatz sequence for a...

    Please answere using python language codes. Write a program to print out Collatz sequence for a user-supplied number. Prompt the user for a positive integer which will become the first number in the sequence. Next number in the sequence is derived as follows: If previous number is odd, the next number is 3 times the previous, plus 1. If previous number is even, the next number is half of the previous According to Collatz proposition, the sequence ultimately reaches 1...

  • What will the code look like for this? (Python) Write an expression that executes the loop...

    What will the code look like for this? (Python) Write an expression that executes the loop body as long as the user enters a non-negative number. Note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds and report "Program end never reached." The system doesn't print the test case that caused the reported message. Sample outputs with inputs: 9 5 2 -1 Body Body Body Done.

  • c++ QUESTION 9 Write a code that ask the user for the number n of decimal...

    c++ QUESTION 9 Write a code that ask the user for the number n of decimal to average. Then n times the code the user to enter all numbers that you save or accumulate each time. Finaly print to the console the average of the n values the user entered using the format: cout << " The average of the " << n << " number you entered is: " << averagedValue <<endl;

  • CODE NEEDS TO BE IN PYTHON. OLA 5: Collatz Sequence Function 12 17 34 Due: Fri...

    CODE NEEDS TO BE IN PYTHON. OLA 5: Collatz Sequence Function 12 17 34 Due: Fri Oct 19, 2018 by 11:59 PM-may be tumed in until Oct 26 by 1159 PM with reduced points (per Open Lab- Project guidance found in the course syllabus) Assignment id: ola5 Assignment type: Project Required Files: ola5.py, myout.log Lab description: In this you will explore the Collatz mathematical sequence. This sequence eventually converges to the value 1, regardless of the initial input Requirements: 1....

  • This MUST be done in C++ Write a program with a loop to ask the user...

    This MUST be done in C++ Write a program with a loop to ask the user for an integer greater than or equal to 2 and then pass the integer to a function which will produce and display on the console the ulam sequence1. Do not accept a number less than 2. 1The ulam sequence begins with an integer. If it is even, divide by 2. If it is odd, multiply by 3 and add 1. Then apply the appropriate...

  • write a program code that asks the user how many numbers they wish to find the...

    write a program code that asks the user how many numbers they wish to find the statistics of and then asks the user to enter those numbers. The program must then calculate and display the average variance and standard deviation of the numbers entered by the user. the program code must -ask three user how many numbers they wish to find the statistics of -ask the user to enter those numbers and store them in an array - use a...

  • 4) (12 points) Write the CH code that continuously (use a loop) prompts a user to...

    4) (12 points) Write the CH code that continuously (use a loop) prompts a user to input a floating point number. Each time, the code prints out the input, numbered. So if the user inputs a -2.3 for the first input and a 116.79 for the second input, the output is input 1: -2.3 input 2: 116.79 The loop keeps running until the sum of all the numbers input is greater than 100. (This needs an accumulator!)

  • Can someone please rewrite this code using a while loop? Please write it in python. #The...

    Can someone please rewrite this code using a while loop? Please write it in python. #The winning number my_number = 12 #variable for the input name user_n = input("Hello! What is your name?") #Ask the user print("Well",user_n,": I am thinking of a number between 1 and 20." + "Take a guess.") user_n = float(input("Take a guess.")) #if statements if user_n == my_number: print("Good job" ,user_n, "You guessed my number!") if user_n > my_number: print("Your guess is high. You lose.") if...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT