Create a python program called code.py. Write a function named total_odds_evens() that takes an integer parameter called num. Your function must use a loop to repeat the following steps num number of times. It randomly selects an integer number x in the range [1 ... 100] (inclusive) an prints whether x is odd or even. It also maintains the sum of all odd x values and the sum of all even x values separately (i.e., saves the results in two different variables). Finally, it returns both sums.
Create a python program called code.py. Write a function named total_odds_evens() that takes an integer parameter called num. Your function must use a loop to repeat the following steps num number of times. It randomly selects an integer number x in the range [1 ... 100] (inclusive) an prints whether x is odd or even. It also maintains the sum of all odd x values and the sum of all even x values separately (i.e., saves the results in two different variables). Finally, it returns both sums.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Expert Solution
Step 1
define a function
i=0
sumeven=0
sumodd=0
while i<num:
x=random.randint(1,101)
if x%2==0:
print(x," is even")
sumeven=sumeven+x
else:
print(x," is odd")
sumodd=sumodd+x
i=i+1
return sumeven,sumodd
call function and pass a number to it.
Step by step
Solved in 3 steps with 1 images
Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education