Python Forum
elif not responding on print
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
elif not responding on print
#1
On the use of elif, the code is not responding to print
here is the code from Spyder (Python 3.11) IDE:

# -*- coding: utf-8 -*-
"""
Created on Thu Jul 20 16:39:11 2023

@author: hp
"""

grade = int(input("Enter the Grade: ")  )

if grade>90:
    print("You Got an AA! Congrats!")
    
elif grade>85 :
    print("You Got an BA! Congrats!")
  
elif grade>80 :
    print("You Got an BB! Congrats!")

elif grade>75 :
    print("You Got an CB! Congrats!")
0n the console response, It print the conditions IF, but not on the condition elif.

Python 3.11.3 | packaged by Anaconda, Inc. | (main, Apr 19 2023, 23:46:34) [MSC v.1916 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.

IPython 8.12.0 -- An enhanced Interactive Python.

runfile('C:/Users/hp/Spyder/What is my Grade.py', wdir='C:/Users/hp/Spyder')
Enter the Grade: 90
You Got an BA! Congrats!

This version of python seems to be incorrectly compiled
(internal generated filenames are not absolute).
This may make the debugger miss breakpoints.
Related bug: http://bugs.python.org/issue1666807

runfile('C:/Users/hp/Spyder/What is my Grade.py', wdir='C:/Users/hp/Spyder')
Enter the Grade: 85

runfile('C:/Users/hp/Spyder/What is my Grade.py', wdir='C:/Users/hp/Spyder')
Enter the Grade: 80

runcell(0, 'C:/Users/hp/Spyder/What is my Grade.py')
Enter the Grade: 75

is it because of this comment on the console? How can this be corrected?
**This version of python seems to be incorrectly compiled
(internal generated filenames are not absolute).
This may make the debugger miss breakpoints.
Related bug: http://bugs.python.org/issue1666807

EddieG
deanhystad write Jul-20-2023, 05:24 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
The order was right, but your comparison is greater than, so the number must be bigger.
Changed the operator to greater equal than.

while True:
    grade = int(input("Enter the Grade: "))

    if grade >= 90:
        print("You Got an AA! Congrats!")
    elif grade >= 85:
        print("You Got an BA! Congrats!")
    elif grade >= 80:
        print("You Got an BB! Congrats!")
    elif grade >= 75:
        print("You Got an CB! Congrats!")
The while True loop is just for easier testing.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#3
@DeaDEyE, the ">" explains why some grades are off, but does not explain why entering 85 or 80 does not appear to produce any output. I am stumped. When I run the program it produces output (the wrong output) when I enter 85 or 80. Or am I mistaken about what is meant by this in the OP:
Output:
runfile('C:/Users/hp/Spyder/What is my Grade.py', wdir='C:/Users/hp/Spyder') Enter the Grade: 85 runfile('C:/Users/hp/Spyder/What is my Grade.py', wdir='C:/Users/hp/Spyder') Enter the Grade: 80 runcell(0, 'C:/Users/hp/Spyder/What is my Grade.py') Enter the Grade: 75
Entering 85 should print "You Got an BB! Congrats!" and entering 80 should print "You Got an CB! Congrats!". These are both incorrect, but there should be a message printed.

From what I can find about the spyder warning, it appears to only affect debugging. Python code runs correctly. What happens if you run you code outside of spyder?
Reply
#4
DeaD_EyE is dead on, as usual!

Try this maybe for clarity?

for grade in range(100, -10, -10):    
    if grade >= 100:
        print("You got an A+! Congrats!")
    elif grade >= 90:
        print("You got an A! Congrats!")
    elif grade >= 80:
        print("You got a B! Congrats!")
    elif grade >= 70:
        print("You got a C! Congrats!")    
    elif grade >= 60:
        print("You got a D! Congrats! Ever heard of the library?")
    elif grade >= 50:
        print("You got an E! Ever heard of studying?")
    elif grade >= 40:
        print("You got an F! Ever read a book?")
    elif grade >= 30:
        print("You got a G! Ever go to the class?")
    elif grade >= 20:
        print("You got an H! Hope your EQ is big!")
    elif grade >= 10:
        print("You got an I! Go back to kindergarten. Do not pass Go, do not collect £100.")
    else:
        print("You got NOTHING! Congrats! You won a pointy hat with a large D on it!")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pygame Rect Not Responding SomebodyImportant 1 1,543 May-02-2021, 01:27 PM
Last Post: BashBedlam
  IDLE stops responding upon saving tompi1 2 1,947 Oct-01-2020, 05:44 PM
Last Post: Larz60+
  Code is not responding abhishek81py 0 1,498 Jul-07-2020, 12:40 PM
Last Post: abhishek81py
  Sublime text not responding Mat 1 1,976 Mar-23-2020, 11:42 AM
Last Post: Fre3k
  IDLE not responding (Mac) Selinal 1 2,973 Aug-05-2019, 10:27 PM
Last Post: Larz60+
  Whats the right way to refactor this Big if/elif/elif ? pitosalas 1 2,257 Jul-28-2019, 05:52 PM
Last Post: ichabod801
  Client Server Game Pygame not responding Damien 2 3,152 Aug-04-2018, 06:19 PM
Last Post: micseydel
  Discord bot not responding to command [New User] Alabaster 0 3,398 May-20-2018, 06:34 PM
Last Post: Alabaster
  [Discord.py] Bot not responding? Ouindoze 2 10,111 Oct-10-2017, 01:35 AM
Last Post: Ouindoze

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020