In: Computer Science
Python Program
Write a program that will ask a user on how many input colored balls of the following codes: R-red, B-blue, W-white, G-green and O-orange -will he or she would like to enter in the program and print the total number of Red balls were encountered. Assume an uppercase and lower case letter will be accepted.
Python code:
#asking for the total number of balls
num=int(input("How many balls would you like to enter: "))
#initializing count of Red balls as 0
count=0
#looping till num
for i in range(num):
#asking for ball
ball=input("Enter the ball: ")
#checking if it is red
if(ball=='R' or ball=='r'):
#incrementing count of Red balls
count+=1
#printing Number of Red balls
print("Number of Red balls =",count)
Screenshot:
Input and Output: