Daniel Andrews
Daniel Andrews

Reputation: 43

How to declare variables inside the method (Python)

def intro():
   print("This program computes payroll based on")
   print("over time rate of ", overTime, " after ", workWeek, " hours")
   name = input("Enter employees name: ")
   hours = (int(input("Enter hours worked: ")))
   rate = input("Enter rate: ")

enter image description here

Upvotes: 0

Views: 177

Answers (1)

Hisagr
Hisagr

Reputation: 621

Whereas it's considered to be a bad practice and in most cases you should avoid using global variables, you can use "global" to reach your variable inside the function.

Like this:

global name
name = input("string") 

Upvotes: 1

Related Questions