Practical Task Challenge Homework 2
Practical Task Challenge Homework 2
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.
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.
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
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.
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.
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.
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: