In: Computer Science
###########
##4. The following code contains several nested if-else statements. Unfortunately,
it
##was written without proper alignment and indentation. Rewrite the code and use
the
##proper conventions of alignment and indentation.
## Start with input('Enter integer score: ') for the variable score.
##A_score = 90
##B_score = 80
##C_score = 70
##D_score = 60
##if score >= A_score:
##print('Your grade is A.')
##else:
##if score >= B_score:
##print('Your grade is B.')
##else:
##if score >= C_score:
##print('Your grade is C.')
##else:
##if score >= D_score:
##print('Your grade is D.')
##else:
##print('Your grade is F.')
#########################
##5. Write an if-else statement that assigns True to the again variable if the
##score variable is within the range of 10 to 59. If the score variable’s value
##is outside this range, assign False to the again variable. Print the answer.
##Start your code with the following:
##test1 = int(input('Enter your test1 score: '))
##test2 = int(input('Enter your test2 score: '))
##HW = int(input('Enter your homework score: '))
##CW = int(input('Enter your classwork score: '))
##totals = 0.25*test1 + 0.25*test2 + 0.35*HW + 0.15*CW
##...... write your code here ......
##print('Is it true that I have to repeat the course again?' , again )
##########################
##6. Write nested decision structures that perform the following: If amount1 is
##greater than 10 and amount2 is less than 100, display the greater of amount1
##and amount2.
##Solution:
##if amount1 > 10 and amount2 < 100:
## if amount1 > amount2:
## print (amount1)
## elif amount2 > amount1:
## print (amount2)
##else:
## print('Both values are the same.')
##
####6.1. Further extension of 6. Write nested decision structures that perform the
##following: If amount1 is greater than 10 and amount2 is less than 100,
##display the greater of amount1 and amount2 if the difference between them is
##more than 33, if not - display the minimum of these amounts.
##Start with input('Enter integer amount1: ') and input('Enter integer amount2: ')
##for these amounts.
##Write your code here:
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks
#code
#Question 4
#reading score as an integer
score=int(input('Enter integer score: '))
A_score = 90
B_score = 80
C_score = 70
D_score = 60
#finding the grade
if score >= A_score:
print('Your grade is A.')
else:
if score >= B_score:
print('Your grade is
B.')
else:
if
score >= C_score:
print('Your grade is C.')
else:
if score >= D_score:
print('Your grade is D.')
else:
print('Your grade is F.')
#Question 5
test1 = int(input('Enter your test1 score:
'))
test2 = int(input('Enter your test2 score:
'))
HW = int(input('Enter your homework score:
'))
CW = int(input('Enter your classwork score:
'))
totals = 0.25*test1 + 0.25*test2 + 0.35*HW + 0.15*CW
#since the variable is totals and not score, I'm checking that
only
if totals>=10 and
totals<=59:
#setting again to True
again=True
else:
#again to False
again=False
print('Is it true that I have to repeat the course
again?' , again )
#Question 6
if amount1 > 10 and amount2
< 100:
if amount1 > amount2:
print (amount1)
elif amount2 >
amount1:
print (amount2)
else:
print('Both
values are the same.')
#Question 6.1
#reading amounts
amount1=int(input('Enter integer amount1:
'))
amount2=int(input('Enter integer amount2:
'))
#checking if amount1 is greater than 10 and amount2 is less
than 100
if amount1>10 and
amount2<100:
#finding the absolute difference between
amount1 and amount2 (positive difference)
diff=abs(amount1-amount2)
#if difference is greater than 33,
displaying greater value among amount1 and amount2
if diff>33:
if
amount1 > amount2:
print(amount1)
elif
amount2 > amount1:
print(amount2)
else:
print('Both values are the same.')
#otherwise displaying smaller value among
amount1 and amount2
else:
if
amount1 < amount2:
print(amount1)
elif
amount2 < amount1:
print(amount2)
else:
print('Both values are the same.')