Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 15
Welcome to our forum. We don't do homeworks here as such since we have a lot of other assignments to complete :) Post your attempt here first. Also please go through this https://www.sololearn.com/discuss/333866/?ref=app https://www.sololearn.com/Discuss/1316935/?ref=app
11th Aug 2020, 3:33 PM
Aditya
Aditya - avatar
+ 11
Chaitra C that's fine.. but give a try first..if it fails.. you can post it..and ask it to anyone :D Well the difference between for and while loops are explained clearly above.. you can also go through this in addition with it The while loops keeps terminating the code inside it until it evaluates to false and for loop is used for performing operations on each item of the list or iterating it a given number of items. Example 1: while True: print("Hello world") #this will print it repeatedly because the condition will remain always true. Example 2: for i in range(10): print ("Hello world") #it will print Hello world ten times.
11th Aug 2020, 3:43 PM
Aditya
Aditya - avatar
+ 3
For loop: https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2435/ While loops https://www.sololearn.com/learn/Python/2281/ For i in range10: is the same as i=0 while(i<10) i+=1 But you can also do: For i in [1,5,3]: i will be 1, then 5, then 3 Given this: Try, show us your attempt, and we will help to solve issues!👍
11th Aug 2020, 3:39 PM
Alexander Thiem
Alexander Thiem - avatar
+ 2
what is this supposed to be? A challenge? Then remove it and post it in personal feed! A problem you have which you want to solve? Show your attempt and we can would like to help you improving it! A question? Then elleberate your question I only see an order....
11th Aug 2020, 3:33 PM
Alexander Thiem
Alexander Thiem - avatar
+ 2
Use a counter and add numbers like - sum += n print (sum) 🤨
13th Aug 2020, 10:23 AM
Sanjay Kamath
Sanjay Kamath - avatar
+ 1
It is similar to i in[2,5,3] For word in [hello,world,spam,eggs]: word will be a different word of those words each iteration, In the first iteration word=hello, then word=world, then word=spam, then word=eggs
11th Aug 2020, 3:45 PM
Alexander Thiem
Alexander Thiem - avatar
+ 1
I dont understand what you mean with: „So the word list is as same as words list right.?“
11th Aug 2020, 3:48 PM
Alexander Thiem
Alexander Thiem - avatar
+ 1
You can try to understand it through english language: For every word in the words: Do something (print the word) Generall: For every item of the list: Do something (print the item)
11th Aug 2020, 3:50 PM
Alexander Thiem
Alexander Thiem - avatar
+ 1
sum=0 for i in [1,2,3,4,5]: sum+=i print(sum) results in 15
11th Aug 2020, 4:11 PM
Alexander Thiem
Alexander Thiem - avatar
+ 1
you are welcome ☺️
11th Aug 2020, 4:13 PM
Alexander Thiem
Alexander Thiem - avatar
+ 1
Chaitra C It's a pretty easy task to do especially with python. However, you should show your attempt at this task so we can correct you where necessary. Doing the whole task for you on here won't help you improve.
12th Aug 2020, 10:11 AM
👑 Tchybooxuur!
👑 Tchybooxuur! - avatar
+ 1
Many replies here with for loops. If you are looking for an alternative to easily sum a given list of any length we have the *: def result(*nums): return sum(nums) result(1,2,3,4,5) good luck on your learning.
13th Aug 2020, 12:54 AM
CarliDe
CarliDe - avatar
+ 1
The basic approach to solve this problem is to go through every element in list using for loop. lst is a list of numbers and n will iterate through every element in list. sum = 0 For n in lst: sum = sum + n print(sum)
13th Aug 2020, 7:13 AM
Yaman Birla
Yaman Birla - avatar
0
If we want to add them we dont have words but numbers, in the list. We then declare a variable sum. sum=0 For i in numbers: sum+=i
11th Aug 2020, 3:57 PM
Alexander Thiem
Alexander Thiem - avatar
0
which numbers do you eant to add?
11th Aug 2020, 4:08 PM
Alexander Thiem
Alexander Thiem - avatar
0
sum=0 for i in [3,7,5]: sum+=i print(sum) results in 15
11th Aug 2020, 4:09 PM
Alexander Thiem
Alexander Thiem - avatar
0
i = 0 list=[1,2,3] for num in list: i += num print(i)
12th Aug 2020, 5:31 AM
Random Gaming
Random Gaming - avatar
0
For example List=[1,2,3] Sum=0 For i in list: Sum= sum+ i Print(sum)
12th Aug 2020, 9:24 AM
Kanpariya Divyang
Kanpariya Divyang - avatar