0
Print name and age with new line
20 Antworten
+ 1
def newline():
age1 = 12
age2 = 23
age3 = 15
age4 = 16
name_age = [age1, age2, age3 , age4];
for index in range(len(name_age)):
print(name_age[index]);
newline();
This code is working fine. There is no problem or you didn't define your problem clearly.
+ 7
Thile Dorje Lama ,
this is a complete *re-post* from you that was already posted same days ago.
you may have *deleted* the former post, since nobody has given you a *ready-made code*.
for this former post i have asked you to show a *serious code try* done by yourself. this is still pending !!
+ 6
Thile Dorje Lama ,
*this is the question you have posted initially* :
age = ('she', 12, 'he', 23, 'I', 15, 'you', 16)
# result should print out with new line, like this
# she 12
# he 23
# I 15
# you 16
>>> now you have *overwritten* this by a code sample that has *no relation* to the initial question.
??? how can you expect to get useful help by creating such a chaos ???
+ 5
Thile Dorje Lama ,
show us your try so that we can see what the issue is.
hint: we can achieve the task by using a for loop.
+ 4
Thile Dorje Lama
Use for loop and check if type of value is int then print new line.
+ 3
Thile Dorje Lama
Read about print, list slicing, for loops, range, variables and index in SoloLearns Python course. Then:
Use slices to get two element at the time from the list. Use the for loop to change the indices in the list slice. Use range in the for loop to get only even indices to changing the slice index. And then print the elements for the sliceced list at every loop.
+ 3
How did you try can you show?
+ 3
Thile Dorje Lama
I think this was not your actual requirement.
in first requirement you had only one list but here two different list.
+ 2
Yes but first you need to show your attempt so we can tell where is the issue
+ 2
Asim Farheen.{-<-{R #, P #, R #, P# & KP#}->-}
Don't copy question to give answer.
+ 2
# DIVYANSH VIDHANI !
# If you have two collections, it’s more easy to do like this:
ages = 12, 23, 15, 16
pronouns = 'she', 'he', 'I', 'you'
for x, y in zip(pronouns, ages):
print(x, y)
+ 1
Solution:
def newline():
age1 = 12
age2 = 23
age3 = 15
age4 = 16
name_age = [age1, age2, age3 , age4]
l=["she","he","I","you"]
for index in range(len(name_age)):
print(l[index],name_age[index])
newline()
0
Example
0
I could solve it
0
I mean I couldn't solve it
0
def newline(age):
age = ['she', 12, 'he', 23, 'I', 15, 'you', 16]
print(age)
# result should print out in this way.
she 12
he 23
I 15
you 16
# not in this way.
she 12, he, 23, I, 15, you, 16
0
It's strange that you have completely completed the basic course in Python and can not solve such a simple problem... 🤔
0
I tried but couldn't solve
0
I really need help over my question
Can anyone please help me over
0
Thanks