'KeyError: 'a' while writing a program in python
a=input('enter the name\n')
b=input('enter the age\n')
print('your name is {a} and your age is {b}'.format(a,b))
I am running above piece of code and I am getting below error in python:
Traceback (most recent call last):
File "main.py", line 4, in <module>
print('your name is {a} and your age is {b}'.format(a,b))
KeyError: 'a'
Solution 1:[1]
you're combining two different syntax. try one of the following:
print('your name is {} and your age is {}'.format(a,b))
or
print(f'your name is {a} and your age is {b}') # notice the f in the begining
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nullman |
