Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I'm a beginner in programming so I wish you be kind to my question :)
would you please tell me what is the output of this simple code?
It shows error but many say the output is " Learn PY 23 "
how is that possible?!
**def m(name,age=20)
print(name,age)
m("learnPY",23)**
By considering your code as below(removed **)
def m(name,age=20)
print(name,age)
m("learnPY",23)
In function m argument age is given default value, which is applied only if you don't pass 2nd argument while calling function.
In your code you have it with 23 so,
the output will be "LearnPY 23"
If you call m("learnPY") then
the output will be "LearnPY 20"
The code is not syntactically legal Python code.
Hence, the question "what is the output of this Python code" is non-sensical, because it isn't Python code.
Yes, it is. The thing is that the code is wrong formatted.
def m(name,age=20):
print(name,age)
m("learnPY",23)
If you run it correctly, it will work. This is because you're calling the function passing two arguments that will be printed.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
In python, I wrote a program to compare two strings.
The coedes are below
d = data.iloc[0]
cmpdate = d['quant_date']
print(cmpdate)
if (cmpdate=='2010-03-18'):
print("=================", dt)
else:
print("xxxxxxxxxxxxx", cmpdate)
the results are
2010-03-18
xxxxxxxxxxxxx 2010-03-18
tow strings are exactly same.
what is the problem?
TIA
Make sure you convert both of the dates to datetime format
and check the result
use to_datetime() function
This works fine
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
How do I search and replace using built-in Python methods?
For instance, with a string of appleorangegrapes (yes all of them joined),
Replace "apple" with "mango".
The .replace method only works if the words are evenly spaced out but not if they are combined as one. Is there a way around this?
I searched the web but again the .replace method only gives me an example if they are spaced out.
Thank you for looking at the problem!
This works exactly as expected and advertised. Have a look:
s = 'appleorangegrapes'
print(s) # -> appleorangegrapes
s = s.replace('apple', 'mango')
print(s) # -> mangoorangegrapes
The only thing that you have to be careful of is that replace is not an in-place operator and as such it does not update s automatically; it only creates a new string that you have to assign to something.
s = 'appleorangegrapes'
s.replace('apple', 'mango') # the change is made but not saved
print(s) # -> appleorangegrapes
replace can work for any string, why you think that it doesn't, here is the test:
>>> s='appleorangegrapes'
>>> s.replace('apple','mango')
'mangoorangegrapes'
>>>
Don't you see that you received your expected result?
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I have a dict as follows:
replace={'/':',',':':','}
Now when I execute the below code
for key in replace:
print(Value)
it gives the following output,
>>:
>>:
I am using Python 3.5.2 and I am also new to using dicts. I expected the output to be
>>,
>>,
What am I doing wrong here ?
Please help.
for value in replacements.values():
print(value)
This is a way to get value for a given key in Python:
replacements={'/':',',':':','}
for key in replacements:
print(replacements[key])
You should do this instead:
for k in replacements:
print(replacements[k])
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
inputs = []
iterations = int(input())
for x in inputs:
currentInput = input()
inputs.append(currentInput)
print(x)
That code isn't working. It is supposed to make more "currentInput" variables based on "iterations". Thank you soooo, much, as this has been bugging me.
Your code isn't working because it's not right.
Your for loop is going through each element in the list inputs. But inputs is an empty list; you haven't added anything to it so the for loop won't work. You must have meant
for x in range(iterations):
currentInput=input()
inputs.append(currentInput)
print(currentInput)
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
i've been writing this program for encryption of messages by ceasar's method, but i have a major problem with this error. it is supposed to change the string b into c and c has to be encrypted. however nothing shows up in tkinter.i have seen several similar question regarding this error but none seemed to have any connection to this case.could someone help??here is the code.
def encrypt(event):
global top,c,root,e
a=e.get()
b=l.get()
top.destroy()
c=''
mystring=StringVar()
mystring.set(c)
for i in b:
if ord(i)in range(65,91) or ord(i) in range(97,123):
if ((ord(i)+a%26)>90 and ord(i)<=90) or (ord(i)+a%26)>122:
c=c+chr(ord(i)+a%26-26)
else:
c=c+chr(ord(i)+a%26)
else:
c=c+i
mystring.set(c)
Label(root,textvariable=mystring,bg='blue',fg='white',font=("Helvetica", 30)).pack()
root.update()
e.get() probably is returning a string. You have set a = e.get then, later on, you do a % 26. The % is modulo for an int, but is string formatting for a string. If a isn't a proper string for formatting (e.g. "There were %s cows!"), it will throw that TypeError. Test this by using IDLE's standard debugger or putting prints to print the value of each variable for testing.