0% found this document useful (0 votes)
467 views2 pages

Starting Out With Python: Sample Output

This document provides a sample Python programming problem and solution for beginners to practice generating random integers between 0 and 100, adding the odd numbers, and printing the sum. The problem asks to write a program that prints out a series of random numbers, adds the odd numbers, and displays the total sum. The solution uses the import random and random.randint functions to generate random integers, a for loop to iterate 10 times, conditional logic to check for odd numbers, and prints the running sum and final total.

Uploaded by

Adam Mikitzel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
467 views2 pages

Starting Out With Python: Sample Output

This document provides a sample Python programming problem and solution for beginners to practice generating random integers between 0 and 100, adding the odd numbers, and printing the sum. The problem asks to write a program that prints out a series of random numbers, adds the odd numbers, and displays the total sum. The solution uses the import random and random.randint functions to generate random integers, a for loop to iterate 10 times, conditional logic to check for odd numbers, and prints the running sum and final total.

Uploaded by

Adam Mikitzel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Starting Out with Python

Here is a collection of easier problems for those of you just starting out with Python. These
problems will be created by me and grade 11's and 12's in the club to help get you started with
the style of competition problems.

1. Write a program that generates a series of random integers between 0 and 100. The program
should add all the odd numbers together and show the sum at the end.

Sample Output

11
8
3
21
4
0
2
12
96
43

Sum is 78

Hints: use import random as the first line of code and also use the command
random.randint(0,100) to generate a random integer in the appropriate range. You could use a
for loop or while loop.

Solution:

#add_random_odd.py
import​ random
sum ​=​ 0
print​ ​(​"Hello world!")
for​ c ​in​ range​(​0​,​10​):
temp ​=​ random​.​randint​(​0​,​100)
if​ ​(​temp ​%​ ​2​ ​==​ ​1​):
print​ ​(​temp​,​"is an odd number")
sum ​=​ sum ​+​ temp
else:
print​ ​(​temp)
print​ ​(​"the sum of the odd numbers is"​,​sum)

You might also like