0
Could you please help me out with this one? How do I get the output separately?
Now that we know how to take user input, let's improve our contact card program that we previously made using variables. Change the given code to take the name and age from user input and use them in the output. name = "Dave" age = "22" print(name + " is "+ age + " years old") name_2 = "Anna" age_2 = "63" print(name_2 + " is " + age_2 + " years old")
14 Antworten
+ 3
The code, "from what I can infer", should be something like this;
name = input()
age = input()
print(name + " is " + age + " years old")
Keep in mind that the output must match the expected output (including capitalization, spacing, and punctuation etc) 100% to pass the test cases. See the descriptions desired output example for comparison, substituting the variables.
+ 3
Finally it worked. ChaoticDawg and your last answer worked for both the cases, that was the crux of the matter. You are a genius man !!
+ 2
When you're getting help like this through the Q&A section or via messages etc, when you make a change to your code and are still having issues, it is best to post you current version of your code along with stating your new and/or current issues. We have no way of knowing if you have made the correct modifications to your code otherwise and the process of helping can become quite tedious and frustrating for all parties involved. Also, as many of the more experienced programmers here on SL don't pay for the Pro subscription, we cannot see the descriptions for pro practices etc.
+ 2
as ChaoticDawg stated, you will need to convert your age and name variable to input and you only need one print statement. one example would look like this:
age=input()
name=input()
string=f”{name} is {age} years old”
Edit: forgot to print. smh
print(string)
as a friendly recommendation, it is best to avoid posting another question within a question. it is more of a courtesy to the community and may actually decrease your chances of your questions being answered.
i hope the responses you recieved help you with your lessons.
+ 1
You need to get name and age as an input(). No need for additional name and age variables. Remove everything below your first print() statement.
+ 1
SoloLearn will run the program for each case. This is why you are getting the input from SoloLearn. So, the first time SoloLearn runs the program, SoloLearn will input "James" and then input "42". Then your program will take those inputs and do what you have coded with them outputting the desired string. It will then re-run the program with the next cases inputs and so on for each case. This is how most of the code coaches, practices, and end of module projects are done.
+ 1
Ok man, sorry to bother you again and again ChaoticDawg . It's just that I am a rookie into this field, will keep that in mind from now onwards.
+ 1
name, age = input(), int(input())
print(f"{name} is {age} years old")
0
So how do I crack this case ?
0
At a time, I am getting only one case corrected.
0
https://www.sololearn.com/Discuss/2819951/?ref=app
The same problem with this case.
Please help me out with such cases.
0
name = input()
age = int(input ())
print(f'{name} is {age} years old')
- 1
But then how do I get the 2nd output i.e. Anna is 63 years old.
I tried this also
name = "James"
age = "42"
name = "Anna"
age = "63"
print(name + " is "+age+" years old")
I need to solve 2 cases in one go. How do I do that ?
Thank you in advance.