Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
No input with a function
#1
I am new to Python and this forum and was wondering if anyone could help me with this problem I'm having with printing functions. I made a function called stats that displays the user's stats but when I put it in a while loop it doesn't work and doesn't print anything. Any help would be greatly appreciated.
This is the function:
def stats():

    print("Health: " + str(BaseHealth), "Luck: " + str(BaseLuck), "Power: " + str(BasePower))
This is the if/elif statement:
if advantage == 1:
    BaseHealth = 150
    stats()

elif advantage == 2:
    BaseLuck = 150
    stats()

elif advantage == 3:
    BasePower = 150
    stats()
Reply
#2
please, post minimal runnable snippet that reproduce the error/problem
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Hello and welcome to Python and the forums!
Please take some care when using code tags next time, I edited the post this time.

We will need to see the whole code in order to be able to help. Post the whole piece, with all the definitons and while loop. In a single pair of Python code tags.
Reply
#4
Thanks for quick replies, I really appreciate it. Here is the full code:
BaseHealth = 100
BasePower = 100
BaseLuck = 100
def stats():

    print("Health: " + str(BaseHealth), "Luck: " + str(BaseLuck), "Power: " + str(BasePower))
valid = {'1', '2', '3'}
advantage = ""
while True:
    advantage = input('Do you pick extra health [1], extra luck [2], or extra power [3]: ')
    if advantage not in valid:
        print('Try again...')
    else:
        print("Your stats have been updated. They are as follows:")
        break

if advantage == 1:
    BaseHealth = 150
    stats()

elif advantage == 2:
    BaseLuck = 150
    stats()

elif advantage == 3:
    BasePower = 150
    stats()
Thanks in advance!
Reply
#5
what you get from input is str, and in if/elif block you check for int
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#6
FYI, this looks like the same person as the poster of this thread - https://python-forum.io/Thread-Unexpecte...-statement
They have the same IP address.
Reply
#7
(May-14-2018, 12:36 AM)micseydel Wrote: FYI, this looks like the same person as the poster of this thread - https://python-forum.io/Thread-Unexpecte...-statement They have the same IP address.
That's my brother
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  difference between forms of input a list to function akbarza 6 1,045 Feb-21-2024, 08:02 PM
Last Post: bterwijn
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,107 Dec-25-2022, 03:00 PM
Last Post: askfriends
  Showing an empty chart, then input data via function kgall89 0 986 Jun-02-2022, 01:53 AM
Last Post: kgall89
  input function question barryjo 12 2,729 Jan-18-2022, 12:11 AM
Last Post: barryjo
  function with 'self' input parameter errors out with and without 'self' called dford 12 3,147 Jan-15-2022, 06:07 PM
Last Post: deanhystad
  Problem with input after function luilong 10 4,117 Dec-04-2021, 12:16 AM
Last Post: luilong
  Exit function from nested function based on user input Turtle 5 2,931 Oct-10-2021, 12:55 AM
Last Post: Turtle
Star I'm getting syntax error while using input function in def. yecktmpmbyrv 1 1,980 Oct-06-2021, 09:39 AM
Last Post: menator01
  Input function cutting off commands at spaces. throwaway34 3 2,213 May-12-2021, 06:40 AM
Last Post: throwaway34
  Defining a function with input abcd 5 3,132 Feb-21-2021, 02:34 AM
Last Post: NullAdmin

Forum Jump:

User Panel Messages

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