Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Basic Doubt in code
#1
Well i can simply put a variable in place of 'n' in square(n) but I tried to allow user to enter a number, but this code is not working and showing this error

Traceback (most recent call last):
File "python", line 10, in <module>
File "python", line 3, in square
TypeError: unsupported operand type(s) for ** or pow(): 'unicode' and 'int'

Code
def square(n):
    squared = n ** 2
    print "%d squared is %d." % (n, squared)
    return squared

n=raw_input("enter a no")
square(n)
Reply


Messages In This Thread
Basic Doubt in code - by prateek3 - Aug-19-2017, 10:56 AM
RE: Basic Doubt in code - by TypesWithSpoons2 - Aug-19-2017, 11:09 AM
RE: Basic Doubt in code - by snippsat - Aug-19-2017, 11:22 AM
RE: Basic Doubt in code - by cygnus_X1 - Aug-19-2017, 11:36 AM
RE: Basic Doubt in code - by prateek3 - Aug-19-2017, 11:57 AM
RE: Basic Doubt in code - by sparkz_alot - Aug-19-2017, 12:14 PM
RE: Basic Doubt in code - by ichabod801 - Aug-19-2017, 01:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I can't for the life of me get this basic If statement code to work CandleType1a 8 248 May-21-2024, 03:58 PM
Last Post: CandleType1a
Question Doubt about conditionals in Python. Carmazum 6 1,702 Apr-01-2023, 12:01 AM
Last Post: Carmazum
  A simple python doubt mohamedrabeek 2 776 Mar-26-2023, 07:24 PM
Last Post: deanhystad
  doubt about python tkinter and sqlite3 LONDER 2 2,205 Aug-14-2021, 08:48 AM
Last Post: ibreeden
  Python Doubt csrlima 5 2,683 Jan-23-2021, 12:23 AM
Last Post: csrlima
  List index out of range error when attempting to make a basic shift code djwilson0495 4 3,084 Aug-16-2020, 08:56 PM
Last Post: deanhystad
  Writing a basic shift code djwilson0495 2 2,328 Aug-16-2020, 01:52 PM
Last Post: djwilson0495
  Python Exercise Doubt azure 4 2,752 Apr-21-2020, 01:15 PM
Last Post: azure
  Doubt in Regex Lookaround fullstop 3 2,449 Feb-03-2020, 09:53 AM
Last Post: Gribouillis
  A doubt with 'in' and 'not in' operators with strings newbieAuggie2019 7 3,699 Oct-23-2019, 03:11 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

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