In: Computer Science
ANSWER IT IN PYTHON
KINDLY ANSWER PROBLEM 2 AND 3. LEAVE PROBLEM 1 OUT.
# General instructions:
'''
I suggest you to read the problem statements first and think how you can solve the problem. Think about your own way. Then check out the hints written as comments. After each hint there should be an empty line. Write your line of code in there to satisfy the comment (you may have to store the the value in a variable but that is not given as a hint).
You can use the if/else code blocks that i have given or get some idea from that. But you have to uncomment, fill the conditions, and choose the correct word if/elif/else).
Please discuss your thoughts and ideas with your group.
'''
#Keep the comments(#) and add additional comments when needed.
# Problem 1
# This problem will ask for the total grade(it should be in between 0 to 100 and an integer) and assign a letter grade for that.
# Grading scale: A: 90-100, B: 80-89, C: 70-79, D: 60-69, F: 0-59
# Ask for a grade between 0 to 100
# Convert it to integer
# if/else block
'''
if(#condition for getting A):
letterGrade = "A"
if or elif(#condition for getting B):
letterGrade = "B"
if or elif(#condition for getting C):
letterGrade = "C"
if or elif(#condition for getting D):
letterGrade = "D"
elif or else:
letterGrade = "F"
'''
#print the letter grade along with the given grade
# Problem 2
# This problem will ask for mode of operation of the calculator and two numbers(a, b). According to that it will perform a mathematical operation.
# Opertions to include addition, subtraction, multiplication, division, remainder
# Ask for the mode
# Ask for a
# Ask for b
# Convert a to float
# Convert b to float
# if/else block
'''
if(# condition for addition):
result = # operation for addition
if or elif(# condition for subtraction):
result = # operation for subtraction
if or elif(# condition for multiplication):
result = # operation for multiplication
if or elif(# condition for division):
result = # operation for division
if or elif(# condition for remainder):
result = # operation for remainder
elif or else:
assert mode == "error", "Operation not found"
'''
# Print out the mode of operation, two numbers and the result.
# Problem 3
# This problem will look ask fr three numbers: a, b, c. This will print out the largest number among them.
# Ask for a
# Ask for b
# Ask for c
# Convert a to float
# Convert b to float
# Convert c to float
# if/else block
'''
if(# condition for a being the largest):
largest = a
if or elif(# condition for b being the largest):
largest = b
elif or else:
largest = c
'''
# print out the three numbers and the largest number among them.
Problem 2
Code
mode = input("Enter the mode ") # Ask for the mode
a = int(input("Enter the value of a ")) # Ask for a
b = int(input("Enter the value of b ")) # Ask for b
a = float(a) # Convert a to float
b = float(b) # Convert b to float
# if/else block
if(mode == '+'): # condition for addition
result = a + b # operation for addition
elif(mode == '-'): # condition for subtraction
result = a - b # operation for subtraction
elif(mode == '*'): # condition for multiplication
result = a * b # operation for multiplication
elif(mode == '/'): # condition for division
result = a / b # operation for division
elif(mode == '%'): # condition for remainder
result = a % b # operation for remainder
else:
assert mode == "error", "Operation not found"
print("{0} {1} {2} = {3}".format(a, mode, b, result)) # Print out the mode of operation, two numbers and the result.
Screenshot
Problem 3
Code
a = input("Enter the value of a ") # Ask for a
b = input("Enter the value of b ") # Ask for b
c = input("Enter the value of c ") # Ask for c
a = float(a) # Convert a to float
b = float(b) # Convert b to float
c = float(c) # Convert c to float
# if/else block
if(a > b and a > c): # condition for a being the largest
largest = a
elif(b > a and b > c): # condition for b being the largest
largest = b
else:
largest = c
print("The Largest among {0}, {1} and {2} is {3} ".format(a,b,c,largest)) # print out the three numbers and the largest number among them.
Screenshot
Comments has been filled with the code without deleting it. Also, screenshot of code as well as the output has been provided for the reference.