+ 1
(Solved)Can I put dict on function ? Because when I put in, variable undefined,
Function
3 Antworten
+ 2
What are trying in code actually? Mention that.
Why are you defining dictionary in function..? It becomes local to function..
Your code won't give any input. Because if condition type(i) == int is always false because your taking input as string type. And x is also a list of strings.. So I value in loop is always a string type.
d.get('i') may through error because d defined in function, undefined outside.
And d.get('i'), here key I is str type but you have to call with int type. So you may need d.get(int(i)).
Hope it helps...
+ 1
Yes,
Can you show your code so that we can find the problem and help you to fix it.
+ 1
word =input()
newword =[]
def dict():
d = {1 : 'one', 2 : 'two', 3 : 'three', 4 : 'four', 5 : 'five', 6 : 'six', 7 : 'seven', 8 : 'eight', 9 : 'nine'}
x = word.split()
for i in x:
if type(i) == int and i <10:
print(d.get('i'))