Question

In: Computer Science

ON PYTHON Exercise 4. Insert one or more conditional statements at the end of the source...

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

Solutions

Expert Solution

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.


Related Solutions

Goals: Concepts related to conditional statements in Python. This is a Python program. You DON’T need...
Goals: Concepts related to conditional statements in Python. This is a Python program. You DON’T need loops for this. Below is the programming task. An employee is paid at a rate of $17.25 per hour for up to 40 regular hours worked in a week. If the employee works more than 40 hours, it is considered overtime. Any hours over 40 hours but less than or equal to 60 are paid at the overtime rate ($12.34 per hour). Any hours...
Design a Python example that includes the following Basic concepts: Loops Conditional statements two of the...
Design a Python example that includes the following Basic concepts: Loops Conditional statements two of the advanced concepts: Encryption / Decryption, Lists / Dictionaries Please leave a Description of the program
Add your own method (or use one or more of the existing methods) to insert the...
Add your own method (or use one or more of the existing methods) to insert the following set of numbers (1, 5, 19, 7, 23, 17, 2) in a linked list (use one function-call per number, and preserve the order of insertion). Once inserted print the linked list such that the output displays the numbers in reverse order. (2, 17, 23, 7, 19, 5, 1) JAVA CODE BELOW class aNode { char data; aNode next; aNode(char mydata) { // Constructor...
is it possible to have more than one ellipse on python turtle.
is it possible to have more than one ellipse on python turtle.
Which one of the following statements describes a meta-analysis? a. It is a primary source of...
Which one of the following statements describes a meta-analysis? a. It is a primary source of evidence, rather than a secondary source. b. It is a narrowly focused search, appraisal and synthesis of research literature to determine best evidence to develop practice guidelines and standards. c. It is a research synthesis strategy that involves statistical analysis to combine samples and results from previous studies to determine the strength of the relationship or the size of the effect of an intervention...
PYTHON ONLY NO JAVA! PLEASE INCLUDE PSEUDOCODE AS WELL! Program 4: Design (pseudocode) and implement (source...
PYTHON ONLY NO JAVA! PLEASE INCLUDE PSEUDOCODE AS WELL! Program 4: Design (pseudocode) and implement (source code) a program (name it LargestOccurenceCount) that read from the user positive non-zero integer values, finds the largest value, and counts it occurrences. Assume that the input ends with number 0 (as sentinel value to stop the loop). The program should ignore any negative input and should continue to read user inputs until 0 is entered. The program should display the largest value and...
Activity 4: Visualizing the Periodicity Insert your graph of one of the periodic trends. How do...
Activity 4: Visualizing the Periodicity Insert your graph of one of the periodic trends. How do I graph this on Excel?
Activity 4: Visualizing the Periodicity Insert your graph of one of the Periodic Trends (atomic radius,...
Activity 4: Visualizing the Periodicity Insert your graph of one of the Periodic Trends (atomic radius, ionization energy or electronegativity) How do I graph this on Excel How would i set this up on Excel What data will I use?
4. [End-to-end Delay] What are the components of end-to-end delay for sending one packet of length...
4. [End-to-end Delay] What are the components of end-to-end delay for sending one packet of length L, over M back to back links, each of transmission rate Ri=R, for i=1,…,M? You do not have any additional information available. A. ML-R B. ML/R C. ML/R D. MPL/R
Which of the following statements is true? Note that more than one of the statements may...
Which of the following statements is true? Note that more than one of the statements may be true. a. Every relation that is in 3NF is in 2NF. b. A relation that is in 2NF, and that has a non-primary-key attribute that is functionally dependent on another non-primary-key attribute is not in 3NF. c. A relation that is in 2NF, and that has a non-primary-key attribute that is transitively functionally dependent on the primary key is not in 3NF. Which...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT