QUESTION IMAGE
Question
programming challenges
- sum of numbers
write a program that asks the user for 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.
input validation: do not accept a negative starting number.
- characters for the ascii codes
write a program that uses a loop to display the characters for the ascii codes 0 through 127. display 16 characters on each line.
- ocean levels
assuming the oceans level is currently rising at about 1.5 millimeters per year, write a program that displays a table showing the number of millimeters that the ocean will have risen each year for the next 25 years.
- calories burned
running on a particular treadmill you burn 3.6 calories per minute. write a program that uses a loop to display the number of calories burned after 5, 10, 15, 20, 25, and 30 minutes.
Step1: Sum of Numbers in Python
while True:
num = int(input("Enter a positive integer: "))
if num > 0:
sum_num = 0
for i in range(1, num + 1):
sum_num += i
print(f"The sum of integers from 1 to {num} is {sum_num}")
break
else:
print("Please enter a positive number.")
Step2: ASCII Codes in Python
for i in range(128):
if i % 16 == 0 and i != 0:
print()
print(chr(i), end=' ')
Step3: Ocean Levels in Python
print("Year\tMillimeters Risen")
for year in range(1, 26):
rise = year * 1.5
print(f"{year}\t{rise}")
Step4: Calories Burned in Python
minutes = [5, 10, 15, 20, 25, 30]
for min in minutes:
calories = min * 3.6
print(f"Calories burned after {min} minutes: {calories}")Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
The above Python - code snippets solve each of the programming challenges as described.