Question

In: Computer Science

########### ##4. The following code contains several nested if-else statements. Unfortunately, it ##was written without proper...

###########

##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:

Solutions

Expert Solution

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.')


Related Solutions

C++: Write correct C++ code for a nested if-else if-else structure that will output a message...
C++: Write correct C++ code for a nested if-else if-else structure that will output a message based on the logic below. A buyer can pay immediately or be billed. If paid immediately, then display "a 5% discount is applied." If billed, then display "a 2% discount is applied" if it is paid in 30 days. If between 30 and 60 days, display "there is no discount." If over 60 days, then display "a 3% surcharge is added to the bill."...
I need these written in shell code 1.nested loop. e.g. 1*2 + 2*3 + 3*4 +...
I need these written in shell code 1.nested loop. e.g. 1*2 + 2*3 + 3*4 + ...(n-1)*n. (Only nested loops) 2.Fibonacci numbers.
Re-write following if-else-if statements as Switch statement. Your final code should result in the same output...
Re-write following if-else-if statements as Switch statement. Your final code should result in the same output as the original code below. if (selection == 10) System.out.println("You selected 10."); else if (selection == 20) System.out.println("You selected 20."); else if (selection == 30) System.out.println("You selected 30."); else if (selection == 40) System.out.println("You selected 40."); else System.out.println("Not good with numbers, eh?"); 2. Write a Constructor for the TrafficLight class that sets stopLight value to “red”, waitLight to “yellow” and goLight to “green”?
Code should be written in C++ using Visual Studios Community This requires several classes to interact...
Code should be written in C++ using Visual Studios Community This requires several classes to interact with each other. Two class aggregations are formed. The program will simulate a police officer giving out tickets for parked cars whose meters have expired. You must include both a header file and an implementation file for each class. Car class (include Car.h and Car.cpp) Contains the information about a car. Contains data members for the following String make String model String color String...
. Consider the following sorting procedure. This procedure uses nested loops to make several passes through...
. Consider the following sorting procedure. This procedure uses nested loops to make several passes through the array. Each pass compares successive pairs of elements. If a pair is in increasing order (or the values are equal), the sorting procedure leaves the values as they are. If a pair is in decreasing order, the sorting procedure swaps their values in the array.  The first pass compares the first two elements of the array and swaps their values if necessary....
VHDL code for a 4 to 2 priority encoder. The structural behavior must be written using...
VHDL code for a 4 to 2 priority encoder. The structural behavior must be written using gates.
Which of the following statements is likely to be true? A)Everything else equal, an increase in...
Which of the following statements is likely to be true? A)Everything else equal, an increase in the supply of dollars in exchange for pesos will cause the dollars to depreciate against the pesos and will decrease the quantity of dollars being traded in the foreign exchange market. B)If a country wants to keep the domestic currency overvalued against a foreign currency, it will buy the domestic currency and sell the foreign currency. C)If a country wants to keep a foreign...
The accounting staff of Pearl Inc. has prepared the following pension worksheet. Unfortunately, several entries in...
The accounting staff of Pearl Inc. has prepared the following pension worksheet. Unfortunately, several entries in the worksheet are not decipherable. The company has asked your assistance in completing the worksheet and completing the accounting tasks related to the pension plan for 2020. Determine the missing amounts in the 2020 pension worksheet, indicating whether the amounts are debits or credits. (Enter all amounts as positive.) Pension Worksheet—Pearl Inc. General Journal Entries Memo Record Annual Pension Expense    Cash OCI—Prior Service...
In what situation would you prefer to implement several alternative logical branches using Multi-Way if/else statements?...
In what situation would you prefer to implement several alternative logical branches using Multi-Way if/else statements? When would you prefer to use Switch?
Which of the following statements is CORRECT? a. The financial manager's proper goal should be to...
Which of the following statements is CORRECT? a. The financial manager's proper goal should be to attempt to maximize the firm's expected cash flows, since that will add the most to the individual shareholders' wealth. b. The financial manager should seek that combination of assets, liabilities, and capital that will generate the largest expected projected after-tax income over the relevant time horizon, generally the coming year. c. The riskiness inherent in a firm's earnings per share (EPS) depends on the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT