DO NOT DEAL WITH THIS MEMBER
This is from our very first class, so I apologize for the simple cringe.
I am trying to write a program in Python that will output my name, favorite color, and number. (Mike, blue, and 13)
Code >>> my_name = "Mike"
>>> fav_color = "blue"
>>> lucky_num = "13"
print(my_name, "favorite color is", fav_color, "and lucky number is", lucky_num)
I was hoping that this would give me the output of: "Mike favorite color is blue and lucky number is 13"
------------------
To cheat I did this:
Code print("Mike favorite color is blue and lucky number is 13")
Any help would be appreciated guys.
**the class meets once a week and this is our only assignment this week.
you need to use a "+" instead of commas when using the variables
DO NOT DEAL WITH THIS MEMBER
(Jan 16, 2018 12:03 PM)XxClassifiedxX Wrote: you need to use a "+" instead of commas when using the variables
So something like this?
Code my_name = "Mike"
fav_color = "blue"
lucky_num = "13"
print(my_name+"favorite color is", fav_color+"and lucky number is"+lucky_num)
I like to use the .format function that belongs to strings. So you could do this/
Code print(“{} favorite color is {} and his lucky number is {}”.format(“Mike”,”blue”,13))
(Jan 16, 2018 02:00 PM)TheMarkMan Wrote: I like to use the .format function that belongs to strings. So you could do this/
Code print(“{} favorite color is {} and his lucky number is {}”.format(“Mike”,”blue”,13))
Please use this rather than concatenating strings
use + instead of commas, it will work then
DO NOT DEAL WITH THIS MEMBER
Jan 21, 2018 07:51 AM
(This post was last modified: Jan 21, 2018 09:09 PM by Cammy.)
(Jan 16, 2018 01:02 PM)Mik3y Wrote: So something like this?
Code my_name = "Mike"
fav_color = "blue"
lucky_num = "13"
print(my_name+"favorite color is", fav_color+"and lucky number is"+lucky_num)
PHP Code
<?php my_name = "Mike" fav_color = "blue" lucky_num = "13" print(my_name + " favorite color is " + fav_color + " and lucky number is " + lucky_num)
But please use string.format instead as suggested above
(Jan 21, 2018 07:51 AM)Cammy Wrote: PHP Code
<?php my_name = "Mike" fav_color = "blue" lucky_num = "13" print(my_name + " favorite color is " + fav_color + " and lucky number is " + lucky_num)
But please use string.format instead as suggested above
So you're giving an example that he should, in your opinion, not use, and instead recommend something that you acknowledge has already been posted? Why are you even posting? No surprise you're at 13k post count.
DO NOT DEAL WITH THIS MEMBER
Jan 21, 2018 08:50 PM
(This post was last modified: Jan 21, 2018 09:06 PM by Cammy.)
(Jan 21, 2018 09:57 AM)Dialog Wrote: So you're giving an example that he should, in your opinion, not use, and instead recommend something that you acknowledge has already been posted? Why are you even posting? No surprise you're at 13k post count.
Because the example I posted is what OP was trying to accomplish with the commas and nobody gave a proper example. It's always good to know about multiple approaches, which ones you shouldn't use and which ones you should. But thanks for your input, prick.
(Jan 16, 2018 02:00 PM)TheMarkMan Wrote: I like to use the .format function that belongs to strings. So you could do this/
Code print(“{} favorite color is {} and his lucky number is {}”.format(“Mike”,”blue”,13))
This would be correct, but you should use your defined variables instead, incase the string value's change.
Code print(“{}, favorite color is {}, and his lucky number is {}”.format(my_name, fav_color, lucky_num))
|