In: Computer Science
ON PYTHON
Exercise 4. Insert one or more conditional statements at the end of the source code listed in exercise4.py that prints the messages ‘You entered a negative number’, ‘You entered a zero’, or ‘You entered a positive number’ based on the value entered by the user.
value = int( input( 'Enter the value: ') )
# insert the additional statement(s) here
Exercise 5. Insert one or more conditional statements at the end of the source code listed in exercise5.py that prints a letter grade that corresponds to test score value. Use the table shown below to determine letter grade that corresponds to a range of scores. score range letter grade 90 to 100 A 80 to 89 B 70 to 79 C 60 to 69 D below 60 F Sample input/output behavior: Enter a score: 83 Your grade is B
score range letter grade
90 to 100 A
80 to 89 B
70 to 79 C
60 to 69 D
below 60 F
"""
score = int ( input( "enter score: " ) )
# insert the additional code here
Exercise 4 :
value = int(input('Enter the value: '))
if value <0:
print('You entered a negative number')
elif value>0:
print('You entered a positive number')
else:
print('You entered a zero')
Explanation-
1.We prompt user to enter the value using input function. since input function reads the value in string format we use int function to convert string into int. We then store the value in variable value.
2.We use if conditional statement to check if value is less than 0 , if condition is true then we print -You entered a negative number.
3.if condition in point 2 is False then we check if value is greater than 0 . if this condition is true then we print-You entered a positive number..
4.if both the conditions in point 2 and point 3 is False , that means it is neither postive nor negative , it is zero.so we print-You entered a zero
Exercise 5 :
score = int (input("enter score: " ))
if score >=90:
print('Your grade is A')
elif score>=80 and score<=89:
print('Your grade is B')
elif score>=70 and score<=79:
print('Your grade is C')
elif score>=60 and score<=69:
print('Your grade is D')
else:
print('Your grade is F')
Explanation-
1.We prompt user to enter the score using input function. since input function reads the score in string format we use int function to convert string into int. We then store the score in variable score.
2.We use if conditional statement to check if score is greater than or equal to 90 , if condition is true then we print -Your grade is A.
3.if condition in point 2 is False then we check if score is greater than or equal to 80 and less than or equal to 89. if this condition is true then we print-Your grade is B.
4.if condition in point 3 is False then we check if score is greater than or equal to 70 and less than or equal to 79. if this condition is true then we print-Your grade is C.
5.if condition in point 4 is False then we check if score is greater than or equal to 60 and less than or equal to 69. if this condition is true then we print-Your grade is D.
6.if all the above conditions are False then it means score is less than 60 and we print-Your grade is F.