Python Forum
Problem with defining a function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with defining a function
#5
You are running all code in interactive shell(>>>).
You need to open a New File window,look at this .
Then whole code need to be without >>>.
You save eg grades.py and Run with F5.
counter = 0
PassCounter = 0
FailCounter = 0
Average = 0
#This function does the calculations
def Calc(): 
    MidGrade = int(input("Your mid-term grade is: "))
    print (str(MidGrade) + "%")
    FinGrade = int(input("Your Final grade is: "))
    print (str(FinGrade) + "%")
    WeightedMid = MidGrade*.4
    WeightedFin = FinGrade*.6
    global Average
    Average = WeightedMid + WeightedFin
 
#This function outputs the necessary information  
def Output():
    print ("Your Average is: " + str(Average) + "%")
    counter = + 1
    if Average > 59.99:
        print ("You have passed the course!")
        global PassCounter
        PassCounter = + 1
    else:
        print ("You have failed the course.")
        global FailCounter
        FailCounter = + 1
    print ("Number of grades calculated: " + str(counter))
    print ("Number of students who have passed: " + str(PassCounter))
    print ("Number of students who have failed: " + str(FailCounter))
 
print (Calc())
print (Output())
I may come back with suggestion to fix stuff that are not good in this code.
Reply


Messages In This Thread
Problem with defining a function - by snow_y - Nov-25-2018, 06:35 PM
RE: Problem with defining a function - by snow_y - Nov-25-2018, 08:56 PM
RE: Problem with defining a function - by snippsat - Nov-26-2018, 02:13 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Conjugate Gradient having issues with defining A (function to solve [A]{x} = {b} ) DimosG 2 2,850 Sep-21-2021, 08:32 PM
Last Post: 1968Edwards
  Defining a function with input abcd 5 3,156 Feb-21-2021, 02:34 AM
Last Post: NullAdmin
  When Defining a Function with an Equation as a Default Argument, which Value Is Used? OJGeorge4 4 2,721 Apr-09-2020, 08:48 AM
Last Post: DeaD_EyE
  Problem defining a variable rix 6 3,244 Dec-17-2019, 11:34 AM
Last Post: rix
  A problem with defining variables meru120 5 3,445 Apr-16-2019, 03:13 PM
Last Post: buran
  IDLE indenting 29 columns after defining function Cosmo_Kane 1 2,441 Jun-03-2018, 08:53 AM
Last Post: Larz60+
  Defining a Function mattt1998 4 3,448 Dec-14-2017, 07:02 AM
Last Post: buran
  Defining an fsolve function to call later hegdep 1 3,094 Oct-25-2017, 07:38 AM
Last Post: hegdep
  init vs_init_ while defining method/function? hsunteik 1 3,674 Dec-24-2016, 08:27 AM
Last Post: micseydel

Forum Jump:

User Panel Messages

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