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
Lynna [10]
3 years ago
11

Write a program asks the user for an integer N and then adds up the first N odd integers. For example, if the user asks the sum

of the first 10 odd integers, the program computes: Use a loop for this. Use instructions and pseudo instructions up to chapter 24. Use exception handler services for input and output. How many odd numbers: 10 The sum: 100 If the user enters a negative integer or non-integer, just print a zero. Start your source file with comments that describe it:
Computers and Technology
1 answer:
abruzzese [7]3 years ago
7 0

Answer:

The program in Python is as follows:

while True:

   try:

       num = input("Number of odds: ")

       num = int(num)

       break

   except ValueError:

       print("Invalid integer! ...")

sum = 0

odd = 1

if num > 0:

   for i in range(num):

       sum+=odd

       odd+=2

print("Total:",sum)

Explanation:

This is repeated until a valid integer is inputted

while True:

This uses exception

   try:

This gets the number of odd numbers

       num = input("Number of odds: ")

This converts the input to integer

       num = int(num)

       break

If input is invalid, this catches the exception

<em>    except ValueError:</em>

<em>        print("Invalid integer! ...")</em>

This initializes sum to 0

sum = 0

This initializes odd to 1

odd = 1

If input is positive

if num > 0:

This add the first num odd numbers

<em>    for i in range(num):</em>

<em>        sum+=odd</em>

<em>        odd+=2</em>

This prints the total

print("Total:",sum)

You might be interested in
What will save you the most money when trying to reduce the cost of college
julia-pushkina [17]

most probably housing and food

6 0
3 years ago
Read 2 more answers
What does this sign mean?
yKpoI14uk [10]
A. yield to the car on your right
8 0
3 years ago
Read 2 more answers
Drag each tile to the correct box.
garri49 [273]
I think select the video insert select the movie option under illustrations resize the video player then select the insert tab i’m not 100 percent sure tho
8 0
3 years ago
Read 2 more answers
What is the name given to software that decodes information from a digital file so that a media player can display the file? har
KiRa [710]

Answer:

plug-in

Explanation:

A Plug-in is a software that provides additional functionalities to existing programs. The need for them stems from the fact that users might want additional features or functions that were not available in the original program. Digital audio, video, and web browsers use plug-ins to update the already existing programs or to display audio/video through a media file. Plug-ins save the users of the stress of having to wait till a new product with the functionality that they want is produced.

6 0
2 years ago
Questions: What memory modules are needed if the customer wants 3 GB of RAM? What capacities and how many modules of each capaci
zhannawk [14.2K]

Answer:

You could use three 1 GB modules.

4 0
2 years ago
Other questions:
  • Maria found a cupcake recipe on a cooking blog. However, she would like to read comments and suggestions before she begins bakin
    6·2 answers
  • A company wants a recruiting app that models candidates and interviews; displays the total number of interviews each candidate r
    6·1 answer
  • When performing a basic search with Bing, you first type in your search expression and then click a button to begin the search;
    13·1 answer
  • Which of the following statements represents the number of columns in a regular two-dimensional array named values?
    9·1 answer
  • What has information technology made piracy possible?
    14·1 answer
  • As photography developed, a variety of materials were employed as image capture surfaces. Choose the correct order
    7·1 answer
  • Write a function called printBackwards() that will work with a C string. The function will print any C string backwards. You don
    13·1 answer
  • Which of the following is a table which can be rearranged to analyze data in a variety of ways?
    13·1 answer
  • he attributes for an iframe are controlled by CSS. One of the iframe controls is "seamless." This means it _____. will blend the
    11·1 answer
  • Which term refers to the science that specifies the design and arrangement of items you use so you interact with the items effic
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!