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")

24th Jun 2021, 1:43 AM
Sanchit Bahl
Sanchit Bahl - avatar
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.
24th Jun 2021, 2:30 AM
ChaoticDawg
ChaoticDawg - avatar
+ 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 !!
24th Jun 2021, 2:52 AM
Sanchit Bahl
Sanchit Bahl - avatar
+ 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.
24th Jun 2021, 2:26 AM
ChaoticDawg
ChaoticDawg - avatar
+ 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.
24th Jun 2021, 2:29 AM
you are smart. you are brave.
you are smart. you are brave. - avatar
+ 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.
24th Jun 2021, 1:54 AM
ChaoticDawg
ChaoticDawg - avatar
+ 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.
24th Jun 2021, 2:10 AM
ChaoticDawg
ChaoticDawg - avatar
+ 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.
24th Jun 2021, 2:44 AM
Sanchit Bahl
Sanchit Bahl - avatar
+ 1
name, age = input(), int(input()) print(f"{name} is {age} years old")
24th May 2022, 4:09 PM
Mazitov Radmir
Mazitov Radmir - avatar
0
So how do I crack this case ?
24th Jun 2021, 2:14 AM
Sanchit Bahl
Sanchit Bahl - avatar
0
At a time, I am getting only one case corrected.
24th Jun 2021, 2:17 AM
Sanchit Bahl
Sanchit Bahl - avatar
0
https://www.sololearn.com/Discuss/2819951/?ref=app The same problem with this case. Please help me out with such cases.
24th Jun 2021, 2:18 AM
Sanchit Bahl
Sanchit Bahl - avatar
0
name = input() age = int(input ()) print(f'{name} is {age} years old')
25th Jun 2021, 4:13 AM
Dasari Navyateja
Dasari Navyateja - avatar
25th Jun 2021, 12:47 PM
Abhishek Kumar
Abhishek Kumar - avatar
- 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.
24th Jun 2021, 2:04 AM
Sanchit Bahl
Sanchit Bahl - avatar