1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
9966 [12]
3 years ago
15

Write a function that asks the user to enter a number (i) between 1 - 1000, then calculate the sum of all numbers from 1 to (i).

Mathematics
1 answer:
RoseWind [281]3 years ago
7 0

Answer:

<em>In Python</em>

def sum(num):

      total = 0

      for i in range(1,num+1):

             total = total + i

      print(total)

   

i = int(input("User input [1 - 1000]: "))

if i >= 1 and i <= 1000:

      sum(i)

else:

      print("Invalid User Input")

Step-by-step explanation:

The function is declared here

def sum(num):

The sum is initialized to 0

      total = 0

The following iteration calculates sum from 1 to the user input

      for i in range(1,num+1):

             total = total + i

The total is then printed

      print(total)

   

The main begins here

This line prompts user for input

i = int(input("User input [1 - 1000]: "))

The following if condition ensures that user input is between 1 and 1000

<em>if i >= 1 and i <= 1000:</em>

<em>       sum(i)</em>

<em>else:</em>

<em>       print("Invalid User Input")</em>

You might be interested in
Please help! I'm leaving school and I have to teach myself this!
marusya05 [52]
She could actually miss and get a 0 because 108+72+95/3=91
5 0
3 years ago
What is the measure of
erica [24]

Answer:

C

Step-by-step explanation:

\cos E=\frac{11}{18} \\ \\ E=\cos^{-1} \left(\frac{11}{18} \right) \\ \\ E \approx 52.33^{\circ}

5 0
2 years ago
The number of fruit snacks available per student varies inversely with the number of students. There are 10 fruit snacks for eac
natka813 [3]

Answer:

240 fruit snacks

Step-by-step explanation:

if there's 10 for every student you do 10 times 24 to get 240

5 0
3 years ago
Read 2 more answers
Since it is a terminating decimal, 4.9 is rational?
Rus_ich [418]

Answer:

Yes it is because it's terminating.

Step-by-step explanation:

6 0
3 years ago
Read 2 more answers
How to evaluate 4x for each value of x?
maks197457 [2]
To solve for the actual value, you need more information, but basically, you need to divide both sides of the equation by 4.
6 0
3 years ago
Other questions:
  • How many are 9 raised to 2 ???​
    11·1 answer
  • What is 20x times x​
    12·1 answer
  • Find the quotient. 48a^3bc^2 ÷ 3abc. . .
    11·1 answer
  • 7h=-(2h-18)7h=−(2h−18) solve for h please asap
    8·2 answers
  • Given:<br> A = O, WA = NO, AS = OT.<br><br> SSS<br> SAS<br> ASA<br> AAS
    6·2 answers
  • What is the rate for 46 and 2?
    10·1 answer
  • PLEASE HELP FAST
    7·1 answer
  • Help fast !!!!!!!!!!!
    11·2 answers
  • PLSSS HELPPPP I WILLL GIVE YOU BRAINLIEST!!!!!!
    7·1 answer
  • Write the expression that represents the area of the rectangle shown.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!