0% found this document useful (0 votes)
20 views

Practical Task Challenge Homework 2

The document provides 8 programming tasks that prompt the user for input and perform basic calculations and comparisons on the input. For each task, the user is instructed to write code to complete the task, test their code, and provide a screenshot of the output.

Uploaded by

trungdung160511
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Practical Task Challenge Homework 2

The document provides 8 programming tasks that prompt the user for input and perform basic calculations and comparisons on the input. For each task, the user is instructed to write code to complete the task, test their code, and provide a screenshot of the output.

Uploaded by

trungdung160511
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Complete EACH task. Copy and paste your codes in the given boxes below.

Upload your python


files into the assignment. You CAN write your program code in a single file. Remember to
write your name as a #COMMENT at the beginning of each question!

Step-by-step task
1. Prompt the user for their name
Greet the user.
#Robert
Print ("what is your name?")
Name = input()
Print ("hello",Name)
Test your program and place a screenshot here.

2. Prompt the user for a number.


Display the number the user entered.
#Robert
print ("choose a number")
Usernum = int(input())
print (Usernum)
Test your program and place a screenshot here.

3. The objective of this program is to compare and display the larger input value.
Prompt the user for a number and store in Num1.
Prompt the user for another number and store in Num2.
 Compare if the first number is larger than the second number, state the first
number is larger.
 Elif the second number is larger than the first number, state the second number is
larger.
 Else state that both are the same.
print("Robert")
print ("choose a number")
Num1 = int(input())
print ("choose a seccond number")
Num2 = int(input())
if Num1 > Num2:
print(Num1,"is larger")
elif Num2 > Num1:
print(Num2,"is larger")
else:
print("they both are the same")
Test your program and place a screenshot here.

4. The objective of this program is to calculate the total of 10 given numbers.


Set Counter to 0
Set Total to 0
While Counter is not equal to 10, do the following:
 Prompt the user for a number.
 Add that number into the Total.
 Increase Counter by 1

Display the Total OUTSIDE the while loop.

Test your program and place a screenshot here.


print ("robert")
Counter = 0
Total = 0
while Total < 10:
print ("choose a number")
Usernum = int(input())
Total = Total + Usernum
Counter = Counter + 1
print (Total)

5. The objective of this program is to calculate the total of 5 given numbers that are of
positive values.
Set Count to 0
Set TotalPos to 0
While Count is not equal to 5, do the following:
 Prompt the user for a number.
 Check if the user’s number is larger than 0.
o Add that number into the TotalPos, if yes.
 Increase Counter by 1

Display the TotalPos OUTSIDE the while loop.

Counter = 0
Totalpos = 0
while Counter != 5:
Usernum = int(input("choose a number"))
if Usernum > 0:
Totalpos = Totalpos + Usernum
Counter = Counter + 1
print(Totalpos)
print ("Robert")
Test your program and place a screenshot here.
6. The objective of this program is to calculate how many positive numbers entered
and how many negative numbers entered. The program stops when the number 0 is
entered.
Set CountPos to 0
Set CountNeg to 0
Prompt the user to enter a number and store into the variable UserNum
While UserNum is not equal to 0, do the following:
 Check if the user’s number is larger than 0:
o Increase CountPos, if true.
 ELIF the user’s number is smaller than 0:
o Increase CountNeg, if true.
 Prompt the user for a number and store into the variable UserNum.

Display the CountPos and CountNeg OUTSIDE the while loop.

Countpos = 0
Countneg = 0
print ("enter a number")
Usernum = int(input())
while Usernum != 0:
if Usernum > 0:
Countpos = Countpos + 1
elif Usernum < 0:
Countneg = Countneg + 1
Usernum = int(input("enter a number:"))
print(Countpos,"positive numbers")
print(Countneg,"negative numbers")
print("Robert")
Test your program and place a screenshot here.

7. The objective of this program is to find the largest and smallest value based on the
user’s input. You can assume that all input will be positive.
Set Largest to 0
Set Smallest to 9999
Prompt the user to enter a number.
While the number entered is not 0, do the following:
 Check if the number entered is larger than Largest,
o Set the Largest as the user’s input, if true.
 Check if the number entered is smaller than Smallest,
o Set the Smallest as the user’s input, if true.
 Prompt the user to enter another number.

Display the Largest and smallest number entered by the user.


largest = 0
smallest = 9999
Usernum = int(input("enter a number: "))
while Usernum != 0:
if Usernum > largest:
largest = Usernum
elif Usernum < smallest:
smallest = Usernum
Usernum = int(input("enter a number: "))
print("the largest is",largest ,"the smallest number
is",smallest)
print("Robert")
Test your program and place a screenshot here:

8. The objective of this program is to count the number of odd and even values given
by a user. You can assume that ALL values are positive.
Set EvenCount to 0.
Set OddCount to 0.
Prompt the user to enter a number.
While the number entered is not 0, do the following:
 Check if the remainder when divided by 2 is equal to 0
o Increase EvenCount by 1.
 Else:
o Increase OddCount by 1.
 Prompt the user to enter another number.

Display the EvenCount and OddCount outside the while loop.

Evencount = 0
Oddcount = 0
Usernum = int(input("enter a number :"))
while Usernum != 0:
if Usernum % 2 == 0:
Evencount = Evencount + 1
else:
Oddcount = Oddcount + 1
Usernum = int(input("enter a number :"))
print("you entered", Evencount,"Evencount
and",Oddcount,"Oddcount")
print("Robert")
Test your program and place a screenshot here:

You might also like