Abhik Jain
Abhik Jain

Reputation: 1

I cannot add a square of a number in python dictionary as values

I just wrote a small program to write the square of a number into a dictionary as dictionary value.

a=int(raw_input(“How many numbers do you want to print”))
b=range(a)
c={}

for i in b:
    c[i]=i*i

print c

It gives me this error.

 File "1.py", line 3
    a=int(raw_input(“How many numbers do you want to print”))
                    ^
SyntaxError: invalid syntax

Can anybody please help as I am very new to python.

Upvotes: 0

Views: 51

Answers (2)

Mosharraf Hosain
Mosharraf Hosain

Reputation: 43

The first line of your code a=int(raw_input(“How many numbers do you want to print”)) consists invalid characters.

You used here left and right double quotation mark, two special Unicode character, U+201C and U+201D respectively. But the compilers and interpreters uses quotation mark, U+0022. Normally, in English keyboard, left and right quotation mark is not available directly.

For further clarification, see the difference of their appearance:
Left Double Quotation Mark: “ (tilted)
Right Double Quotation Mark: ” (tilted)
Double Quotation Mark: " (not tilted, straight)

One suggestion, do not copy code(s). If you really need to do so, type manually.

Upvotes: 0

Elham Khan
Elham Khan

Reputation: 71

This line of code:

a=int(raw_input(“How many numbers do you want to print”))

You may have copied it from somewhere else.

Try removing the double quotes and adding it again using your own keyboard. This way the right format of the character "Double Quote" will be inserted.

Upvotes: 2

Related Questions