In: Computer Science
13) Make a program that receives the sex of people like M or F.
At the end, show how many
is male and female. However, if the user types a letter
different from M or F, the program should ask him to type again.
Create a form of
end the program and display the result.
14) Create a program that draws a number between 1 and 10. Right
after, the program must ask
for the user to guess the number drawn. When the user is correct,
display on the screen according to
times he tried. Obs: SEARCH FOR RANDOM NUMBERS IN PYTHON
15) Receive two numbers from the user and display the
menu:
type it
1-Display a sum
2-Display a subtraction
3-Display multiplication
4-Display the division
5-Exit
The user chooses an option, the result of the operation appears on
the screen and the menu is to apply
again, until the user chooses an option 5.
16) Ask if the user wants to enter a temperature in Celsius and
convert to
Fahrenheit, or from Fahrenheit to Celsius. Receive the value,
convert, display the result and
question whether he wants to do another calculation or leave the
program. Use as formulas:
(F - 32) × 5/9 = C
(C × 9/5) + 32 = F
17) Receive and check if the user's network number is triangular
or not. Repeat one
operation until the user enters a number equal to 0. A triangular
number is equal to
sum of first numbers, examples:
6 is a triangular number, because 6 = 1 + 2 + 3
10 is a triangular number, because 10 = 1 + 2 + 3 + 4
15 is a triangular number, because 15 = 1 + 2 + 3 + 4 + 5
18) Given integers n, i and j, all greater than zero, print in
ascending order
the natural first n which are multiples of i or j and or
both.
For example, for n = 6, i = 2 and j = 3 the output should be: 0 2 3
4 6 8
19) In a gymnastics competition, each athlete receives votes
from seven jurors. The best and the
worst score are eliminated. The athlete's score is the average of
the remaining votes. You must
make a program that receives the name of the gymnast and the scores
of the seven jurors achieved by the
athlete in his presentation. Your program should display an
average, as described above
(remove the best and worst jump and then average with the remaining
grades). As notes don't
are reported in order. An example of the program output should be
as the example
below:
Data entered by the user:
Athlete name: Rone Ilídio
Score: 9.9
Score: 7.5
Score: 9.5
Score: 8.5
Score: 9.0
Score: 8.5
Score: 9.7
Result that should be applied:
Athlete: Rone Ilídio
Best grade: 9.9
Worst grade: 7.5
Average: 9.04
Problem 13:
male=0 #to store count of male
female=0 #to store count of female
for i in range(5): #say user needs to enter input for 5 times
sex=input("Enter M for Male or F for Female\n")
while(sex!='M' and sex!='F'):
sex=input("Enter M for Male or F for Female\n") #input till user enter M or F
if sex=='M':
male+=1
elif sex=='F':
female+=1
print("Number of male: ",male)
print("Number of female: ",female)
Output and code screenshot:
Problem 14:
import random
random_number=random.randint(1,10)
guesses=0
flag=True #set flag to true
while flag:
number=int(input("Enter the number: "))
if number==random_number:
guesses+=1
flag=False #set flag to false if number is correct so that block will end
else:
print("Sorry!! Try again!!") #else ask user to enter it again
guesses+=1 #count the guesses every time
print("Number of tries to guess the number",guesses) #print the number of tries to guess the number
Output and code screenshot:
Problem 15:
flag=True #set flag to true
num1=int(input("Enter number 1: ")) #input 2 numbers
num2=int(input("Enter number 2: "))
while flag:
print("1-Display the sum\n2-Display the subtraction\n3-Display the multiplication\n4-Display the division\n5-Exit\n") #display menu
choice=int(input("Enter your choice: ")) #input choice
#calculate based on choices
if choice==1:
print("Sum: ",num1+num2)
elif choice==2:
print("Subtraction: ",num1-num2)
elif choice==3:
print("Multiplication: ",num1*num2)
elif choice==4:
print("Division: ",num1/num2)
elif choice==5: #if choice is 5 then set flag to false. This will exit the block
flag=False
Output and code screenshot:
Problem 16:
flag=True #Set flag to true
while flag:
scale=input("How you want to calculate the temperature? Enter C for Celsius or F for Fahrenheit: ") #input C or F
while(scale!='F' and scale!='C'): #if scale is not C or F ask user to input again
scale=input("How you want to calculate the temperature? Enter C for Celsius or F for Fahrenheit: ")
temp=float(input("Enter the temperature: ")) #input temperature
#caculate based on scale
if scale=='C':
temp=(temp*(9/5))+32
print("Temperature is %.2f F"%(temp))
elif scale=='F':
temp=(temp-32)*(5/9)
print("Temperature is %.2f C"%(temp))
option=int(input("enter 1 to Try again or 0 to exit: ")) #input option to continue or exit
while(option!=0 and option!=1):
option=int(input("enter 1 to Try again or 0 to exit: "))
if option==0:
flag=False
Output and code screenshot:
Dear, we were instructed to solve a max of 4 questions. So please upload the remaining questions separately.
#Please don't forget to upvote if you find the solution helpful. Feel free to ask doubts if any, in the comments section. Thank you.