Navigation

    ask avan logo
    • Register
    • Login
    • Search
    • Categories
    • Unsolved
    • Solved

    ValueError: invalid literal for int() with base 10: '' using input function

    Python
    2
    2
    33
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      RobinAves last edited by avan

      So I am trying to learn int and float by this script I got from a book.
      And it doesn't work 😕

      help.png

      Reply Quote 0
        1 Reply Last reply

      • avan
        avan last edited by

        Hello @RobinAves

        A few things to point out.

        1. input() takes a string to display and the it is up to the user to enter a value. As long as the input is a valid int you should be safe to convert the input to int
        2. To print a variable value you just need to use the literal without quotes.

        Here is a slightly modified version of your code that should work.

        svar = input('Enter a number')
        x =int(svar)
        y = x * x
        print(y) 
        
        Reply Quote 0
          1 Reply Last reply

        • avan
          avan last edited by

          Hello @RobinAves

          A few things to point out.

          1. input() takes a string to display and the it is up to the user to enter a value. As long as the input is a valid int you should be safe to convert the input to int
          2. To print a variable value you just need to use the literal without quotes.

          Here is a slightly modified version of your code that should work.

          svar = input('Enter a number')
          x =int(svar)
          y = x * x
          print(y) 
          
          Reply Quote 0
            1 Reply Last reply

          • First post
            Last post