Question

# Problem: Compare student marks # Input: mark1 as an integer from 0 to 100 #...

# Problem: Compare student marks

# Input: mark1 as an integer from 0 to 100

# Input: mark2 as an integer from 0 to 100

mark1 = 99

mark2 = 97

# Output: answer, a string

if mark1 == mark2 :

    answer = 'Both marks are same'

if mark1 == mark1 - 1

    answer = 'First mark is one less than second'

if mark2 == mark2 - 1

    answer = 'Second mark is one less than first'

if (mark1 - mark2 > 1) or (mark2 - mark1 > 1) :

    answer = 'Marks differ by more than 1'

print(answer)

Question 1: what are the admissible values for the inputs?

b)

i ) What are the syntax errors in this program? Consider no other errors at this point.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

mark1 = 99

mark2 = 97

# Output: answer, a string

if mark1 == mark2 :

answer = 'Both marks are same'

if mark1 == mark1 - 1 #this line contains syntax error

answer = 'First mark is one less than second'

if mark2 == mark2 - 1 #this line contains syntax error

answer = 'Second mark is one less than first'

if (mark1 - mark2 > 1) or (mark2 - mark1 > 1) :

answer = 'Marks differ by more than 1'

print(answer)
#int, float, double values are acceptable
#correct code is
mark1 = 99

mark2 = 97

# Output: answer, a string

if mark1 == mark2 :

answer = 'Both marks are same'

if mark1 == mark1 - 1:
answer = 'First mark is one less than second'

if mark2 == mark2 - 1:
answer = 'Second mark is one less than first'

if (mark1 - mark2 > 1) or (mark2 - mark1 > 1) :

answer = 'Marks differ by more than 1'

print(answer)

main.py 1 mark1 = 99 2 mark2 = 97 3 # Output: answer, a string 4- if mark1 == mark2 : answer = Both marks are same 6 if mar

Add a comment
Know the answer?
Add Answer to:
# Problem: Compare student marks # Input: mark1 as an integer from 0 to 100 #...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Part I Create a Java program that inputs a grade from the user. The grade input...

    Part I Create a Java program that inputs a grade from the user. The grade input from the user will be an integer. Once the input is stored, use an if-else-if block of code to determine the letter grade of the inputted integer grade. Do not use a bunch of if statements by themselves to solve this problem. You will print an error message for inputs greater than 100 and for inputs less than 0. Both errors must be handled...

  • Exception handling to detect input String vs. Integer

    6.6 LAB: Exception handling to detect input String vs. IntegerThe given program reads a list of single-word first names and ages (ending with -1), and outputs that list with the age incremented. The program fails and throws an exception if the second input on a line is a String rather than an Integer. At FIXME in the code, add a try/catch statement to catch java.util.InputMismatchException, and output 0 for the age.Ex: If the input is:Lee 18 Lua 21 Mary Beth 19 Stu 33 -1then the output...

  • Java programming only Create a Java program that inputs a grade from the user. The grade input from the user will be an...

    Java programming only Create a Java program that inputs a grade from the user. The grade input from the user will be an integer. Once the input is stored, use an if-else-if block of code to determine the letter grade of the inputted integer grade. Do not use a bunch of if statements by themselves to solve this problem. You will print an error message for inputs greater than 100 and for inputs less than 0. Both errors must be...

  • 3. Write Python statements that will do the following: a) Input a string from the user....

    3. Write Python statements that will do the following: a) Input a string from the user. *** Print meaningful messages along with your output.* b) Print the length of the String. Example input: The sky is blue. Correct output: The length of the string is 16 Incorrect output: 16 c) Print the first character of the string. d) Print the last character of the string. 4. Save the program. Double-check the left edge for syntax errors or warning symbols before...

  • In C programming Write a program that displays the appropriate prompt to input 5 scores. Once...

    In C programming Write a program that displays the appropriate prompt to input 5 scores. Once the user inputs the five integer values, your program calculates and prints the average. You do not need to declare five different variables, think of how you can get away with a single variable. The second part of this program will print A if the average of these 5 numbers is greater than or equal to 90 but less than 100, B if greater...

  • static public int[] Question() // retrieve an integer 'n' from the console // the first input...

    static public int[] Question() // retrieve an integer 'n' from the console // the first input WILL be a valid integer, for 'n' only. // then read in a further 'n' integers into an array. // in the case of bad values, ignore them, and continue reading // values until enough integers have been read. // this question should never print "Bad Input" like in lab // hint: make subfunctions to reduce your code complexity return null; static public int...

  • UNIX QUESTION Exercise #1. [8 Marks] Create a script that does the following: a. Takes 4...

    UNIX QUESTION Exercise #1. [8 Marks] Create a script that does the following: a. Takes 4 input parameters b. Using the shell special variables print the following: i. The command you executed ii. First input iii. Second input iv. Third input v. Fourth Input vi. Process Id vii. Total number of input parameters [ by querying the system for it ] Exercise #2. [8 Marks] Creates a script that does the following: a. Takes two input parameters b. Using the...

  • Write a program that uses String method regionMatches to compare two strings input by the user....

    Write a program that uses String method regionMatches to compare two strings input by the user. The program should prompt the user to enter two strings, the starting index in the first string, the starting index in the second string, and the number of characters to be compared. The program should print whether or not the strings are equal, (Ignore the case of the characters during comparison.) 四SAMPLE RUN #1: java StringCompare Highlight: None D Show Highlighted Only Interactive Session...

  • USING PYTHON 1. Write a small program that asks for an integer number from the user...

    USING PYTHON 1. Write a small program that asks for an integer number from the user and print all the prime numbers (2,3,5,7,etc) less than the input number. 2. How long it takes for your program to print the prime numbers less than 100. (Use magic functions)

  • Write a program “hw4.c” that reads integer (less than or equal 100) from the keyboard and,...

    Write a program “hw4.c” that reads integer (less than or equal 100) from the keyboard and, on the output, writes the sum of the divisors of n (other than itself). For integers less than or equal to 1 it should print 0. For example, the input -3 0 1 4 5 6 12 should generate the output 0 0 0 3 1 6 16 Explanation of output: The input -3 is less than 1, output is 0. The input 0...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT