Variable assigned but never used? (python) [closed] - python

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 days ago.
Improve this question
`Hello!
I am coding using python and the app I use to code is replit. It gives me a yellow error "local variable 'Age' is assigned to but never used" I have a picture if that explains better. I do not understand why it is saying that. Can someone please help me? Thank you in advance!
Link to Code: https://replit.com/join/nhojkopfys-seungmint
Image 1
Image 2
Honeslty I have changed about everything and I do not know what I am doing wrong. I have fixed my indents and rewrote this multiple times. This is a DIY lab for my class. I have read through the notes, powerpoints, textbook, and have re-coded this multiple times. I do not have a tutor and one of my classmates recommnded this platform.
This is what the code is suppossed to diplay:
//Input
Enter your guess for age: 32
Enter your guess for weight: 119
Enter your guess for birth month: April
//Output
Congratulations, the birth month is April.
Sample 3:
//Input
Enter your guess for age: 58
Enter your guess for weight: 128
Enter your guess for birth month: January
//Output
Congratulations, the weight is 128 or more.

getAge, getMonth and getWeight are functions. If you want to call them, you need to add brackets, like getAge().
So in main(), in checkYes, add brackets to all three arguments

Variables in python have scope. In this case your age, month and weight variables are locally scoped to the function getYes. They dont exist outside it. So you declare them in the function then never use them, then they go out of scope. So it correctly is telling you that you are defining these but not using them.
def getYes():
Age = getAge()
month = getMonth()
weight= getWeight()

Related

How can i create a exam generator program in python 3?

*I'm a newbie to python, I'm currently trying to create some random programs. I came accross this challenge. Would love to see how it can be solved, unfortunately I couldn't make this program.
I understand that we should use the random module and also the file handling functions in python.
If any detail is unclear I can re explain it
Write a program, which will help the user to generate exam tickets.
there are 2 files given . 1) with the exercises(exercises.txt):
it contains 30 exercises, each are already written on a new line.
2) we are given the students.txt file. Each line has a full name of a student. The program should allow the user to input the number of exercises which should be generated for the student. The new created ticket should have the students name with .txt file extension. The number must not exceed 30 exercises, if it does we should give them a new try to input the correct number. The exercises should be shuffled(randomized) .
import random
def logic():
number_input = int(input('sheiyvanet cifri'))
students_file = open('students.txt', 'r', encoding='utf8')
exercises_file = open('exercises.txt', 'r', encoding='utf8')
new_ticket_file = open('newTicket.txt', 'w')
while True:
if(number_input < 30):
new_ticket_file.write(str(random.shuffle(exercises_file.readlines())))
new_ticket_file.close()
break
else :
continue
logic()
Please do not simply provide a question and ask for it to be solved. Instead, show your current work and specify what is wrong with it.
Show examples of the text files, as in a few lines from each so that all viewers can properly understand it.
A good starting step is to write a piece of code that does only one thing. Eg:
Input a number.
The number must not exceed 30 exercises, if it does we should give them a new try to input the correct number.
Then write one that achieves a different part of your question. Try connecting these pieces. If it blows up or you really can't work it out, post a new question with the stuff you made and ask for help.

Intro to Python: Creating a function that tests the validity of 'months'

I have to say thank you in advance to whomever is helping me out here, I recently started learning python a fews days ago and a current problem set we are working on has been quite confusing.
I think it has to do with a fundamental misunderstanding of mine on how parameters are assigned within a function.
As I have briefly mentioned in title, I am being tasked with creating a function is_months_valid(months)
This is what I have done so far, brace yourselves:
def is_valid_month(month):
month = int
if month <= 0:
month == False
print('this is not a valid month')
if month >12:
month = False
print('this is not a valid month')
return month
As you can see what I am trying to do here is create an integer range from 1 to 12 where 'months' is a valid date.
The issue that I have been encountering is this:
'<=' not supported between instances of 'type' and 'int'
I.e a type error, and I think that my issue is that I am having trouble defining my parameter 'months' as an integer that can take any value. And this value, when run through my program presents me with a valid month or a print statement that says that
'this isnt a valid month'
Again, I am not sure how my code appears to anyone outside my perspective but I would appreciate any and all feedback on it.
Thank you
EDIT: Thank you guys my little frankenstein code finally works, for some reason I was under the assumption that in order to have my parameter (month) take any integer value I wanted, I needed to define it as an 'int.'
I know that stackoverflow isnt "help a student with his cs homework.com" but thank you all for your feedback regarding my indentation, the rules of python, and the guidance in the right direction. Coding is something that I want to improve on and hopefully become literate in.
Thank you
Maybe you meant that!
def is_valid_month(month):
if month <= 0:
month = False
print('this is not a valid month')
elif month >12:
month = False
print('this is not a valid month')
else:month=True
return month

Validating user input Python [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
i am new to Python, and i was wondering if i could get some help with a script. I am trying to validate user input with this script. I would like to restrict the user input to only integers for the number of minutes including and between 1 and 10080. I am still learning all of the terminology, but Here is what i have so far. It looks like something keeps getting stuck at while True:, but i can't seem to figure out what. Any help would be greatly appreciated.
Min=int(input("Please enter the amount of minutes used as an integer ")
while True:
try:
Min = int(input('Min'))
if Min < 1 or Min > 10080:
raise ValueError
break
except ValueError:
print("Invalid number of minutes. Please try again. ")
If you fix the syntax error on the first line (missing )) it should work, but it still asks for user input twice. Removing the first line and doing some minor cleanup, we can get:
while True:
try:
minimum = int(input("Enter number of minutes: "))
if minimum < 1 or minimum > 10_080:
raise ValueError
break
except ValueError:
print("Invalid number of minutes. Please enter a value between 1 and 10,080.")
I agree with #MatthewProSkills solution, but his version doesn't account for exceptions. Other answers don't save the variable. Here's an improved version.
minimum = 0
while minimum < 1 or minimum > 10080:
try:
minimum = int(input("Please enter the amount of minutes used as an integer "))
except Exception:
print("Invalid number of minutes. Please try again. ")

?Is there a reason why my program won't perform it's if elif else statement after receiving proper input

Basically, the goal of this program is to take input from the user on what they want to order, process the cost of the item and tack on sales tax and a tip and return that. I'm struggling with how to go about getting my program to take input and run an if elif else statement based on what the input is.
I'm fairly new and I'm still figuring out how to ask a constructive question, so bear with me here. Also, I know there a bits of it that are unfinished, which may factor into it, but I'm not really concerned with the incomplete bits
I've tried making the if statement conditions dependent on the input given using the == operator as well as changing that to an "if answer is __: print a response. I'm fairly confident that I can get the program to print out a tip and tax tacked onto a price, but everything I've tried so far keeps exiting my program after receiving any form of input.
salesTax = 0.07 #the tax added onto the total
tip= 0.18 #the percentage for a tip
steak= 96 # a var for a steak priced so deliciously, that it *must* be good.
goose= 42 #var for the oddly familiar, yet disturbingly alien meal that is goose.
narwhal= 109 #var for a meal that questions its own existence, then laughs in the face of that question
menu = ['high-stakes steak', 'uncanny boiled goose', 'endangered carribrean narwhal caccitore']
print("Tonight's menu at Joe's ethically questionable eatery includes")
print(menu)
input('Hon hon, what\'ll it be, monsieur? the goose, stake or narwhal?')
answer = input
if answer == 'goose':
print("Ah, very good monsieur the cost will be 42. We will beegen ze cooking of ze goose")
elif answer is 'steak':
print("Ah, a high roller, we will begin")
I expect it to take 'goose' as an answer and print a response (eventually i'd make this take the number assigned to goose and calculate tax), but it simply ignores any input every single time.
input is a build-in function, you should assign the value got from input, but your codes assign the function itself to your variable answer
answer = input('Hon hon, what\'ll it be, monsieur? the goose, stake or narwhal?')
You need to assign your input to a variable. Your input is just reading from the keyboard and you don't save that value. Fix this with:
answer = input('Hon hon, what\'ll it be, monsieur? the goose, stake or narwhal?')
if answer == 'goose':

finding friends' birthdays in python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have found help with starting an assignment that I previously did not know how to begin. I currently need to figure out a way to compare several birthdays with the current date, as prompted by the user, with the last day of a month as prompted by the user. I know there is a date timemodule that can tell the current date but I am unsure of how to use the module to work with what the user inputs...if that makes sense.
For example: If the user inputs 11/27/18 as the current date and June as the comparison month (my professor requires a month be entered instead of a date), I need to compare the birthdays from an opened file with 11/27/18 and 06/30/19 and print however many of those dates occur before July 1st, 2019 (it needs to be printed in words, my professor requires specific formatting).
I know how to format the dates that are input in my program, but I am unsure how to compare the dates from the file with what is input for comparison as it could be different every time. Currently what I have now is the inputs of strings where the user would prompt the current date and the month and I have the file opened.
your program would look something like this its not exactly what your criteria is but this is a step in the right direction. This is just one way to do it so someone might have a better program.
FriendList=[" name 1", "name 2"]
PhoneList=[ " 123" , "456"]
Birthday=["January" , "February"]
print(Birthday)
Date=input(" please choose a month or press q to exit")
# in lists the first string or number in each list will be together
# example: if janurary is chosen then name 1 and 123 will appear
while Date != 'q': # runs until q is pressed to quit
for i in range (2):# loop goes through the 2 names in the list
if Birthday[i] == Date: # compares the list of names to the date
print(FriendList[i],"" , Date[i], "" ,PhoneList[i])
Date=input(" please choose a month or press q to exit")
First you need to check the dates, start by figuring out this part: "birthday between the current date and the last day of a month "
Once you have that working, loop through the friends, and if they meet the condition then add them to a new list.
Sort the new list by alphabetical order, and print it.
This should give you an idea of where to start, once you've some code you can post that and ask for help for specific problems, but nobody will do your final for you (that's cheating!)

Categories