name = input("Enter your name: ")
bid = int(input("Enter your bid: "))
bids = {}
for name,bid in bids.items():
bids += { name : bid }
print(bids)
I am getting empty output as {}.
Could you please help me to rectify my error? As a fellow beginner in Python.
name = input("Enter your name: ")
bid = int(input("Enter your bid: "))
bids = {}
for name,bid in bids.items():
bids += { name : bid }
print(bids)
I am getting empty output as {}.
Could you please help me to rectify my error? As a fellow beginner in Python.
If you want a dictionary to store your name and bid values then it's just:
name = input("Enter your name: ")
bid = int(input("Enter your bid: "))
bids = {name: bid}
print(bids)
There is no need for loop, try this easy method, but there are others too:
name=input('Enter your name: ')
bid=input('Enter your bid: ')
dict1={}
dict1[name]=bid
print(dict1)
for name,bid in bids.items():
—bids
is empty, so that loop won’t do anything. You only have one item you want to append anyway, no need for a loop at all. – deceze ♦ Commented Feb 3 at 6:42+=
dictionaries. Usebids[name] = bid
for a single key/value addition orbids.update(other_dict)
to add keys from another dictionary. – Mark Tolonen Commented Feb 3 at 6:51bids = {name: bid}
and you're done. – John Gordon Commented Feb 3 at 17:23