|
Answer» digit = input("Give a Number")
print ("this is a %d") % digit
word = input("Give a String")
print ("this is a %s") % word #print ("this is a %r") % word
# how do you ask for a number and then print it, i can print a number, but not a string # how do you ask for a string and then print itWhat language is this. I ask because it looks like Python but half of it makes no SENSE as Python- and also because you decided to never mentioned what language it was.
What is % supposed to do?PYTHON
i used
%s
in the string to take a string from the VARIABLE which is listed at the end of the string with
% word
thinking that
the variable word would be PUT in place of
%s
and % d use for a digit
and %r use to force either a string or digitCode: [SELECT]print ('digit:%d' % (digit))
(comment powershell for display of output and the NOTEPAD++ to show what was typed to get there)
_______________________________________ _______________________________________ __________________________
I wasn't giving you a working solution. I was giving you the correct syntax. The code sample you provided wouldn't work so I presumed the problem was based on that.
Input will always give you a string, not a number. use either the int() or float() to coerce the result into a numeric type.
|