Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. [4 pts] Write a Python program to: a) Request the user to enter a positive integer; b) Starting from 2, print all positive even

1. [4 pts] Write a Python program to:

a) Request the user to enter a positive integer;

b) Starting from 2, print all positive even numbers that are strictly less than (<) the user input

c) Print numbers in one line but separate them in some way (you decide)

2. [3/4 pts] Write 2 separate Python programs (2A & 2B) to perform the following tasks.

Part A.

a) Request the user to enter a positive integer;

b) Among positive integers that are strictly less than the user input, print & count those divisible by

3 (multiples of 3, i.e., 3, 6, 9, ...)

Part B.

a) Request the user to enter a positive integer;

b) Starting from 1, print all integers that are divisible by 3 or 5 in the ascending order;

c) Stop printing when the number of printed numbers equals the user input in a);

d) Calculate and print the average of all printed numbers.

3. [4 pts] Write a Python program to:

a) Continuously request the user to enter positive numbers, one at a time

b) When the user enters a 0, stop requesting for inputs

c) When the user enters a negative number, exclude it from calculation (instructions provided in d)

and print: "Negative numbers are invalid! Please re-enter."

d) Calculate and print the average of all valid inputs (excluding zero and negative ones).

Hint 1: Use an infinite loop to request for inputs continuously. Use break and if statement together to

terminate that loop when a 0 is input.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions