Python Forum
Basic Python Program for Sequence
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Basic Python Program for Sequence
#7
Steps to Follow:

Use Python input() function to accept the list as an input from a user.
use for loop to iterate over a list
Do your operation in the body of for loop

Your code should be like this
numbers = input("Enter a list element separated by space ")
list  = input_string.split()
list = map(int, list)

#first solution

print(min(list))
print(max(list))

#second problem solution

for i in list:
  if(i%2==0):
     print ("even number- ",i)
  else
     print ("odd number- ",i)

#third problem solution

sum = list[0]
for i in list:
     print ("cumulative sum is - ",sum)
     sum+=i
#4th solution try with yourself :)
Reply


Messages In This Thread
Basic Python Program for Sequence - by patycanes - Mar-21-2017, 05:53 PM
RE: Basic Python Program for Sequence - by Larz60+ - Mar-21-2017, 05:57 PM
RE: Basic Python Program for Sequence - by nilamo - Mar-21-2017, 09:20 PM
RE: Basic Python Program for Sequence - by wavic - Mar-21-2017, 09:40 PM
RE: Basic Python Program for Sequence - by Larz60+ - Mar-22-2017, 01:04 AM
RE: Basic Python Program for Sequence - by vishalhule - Jul-15-2018, 08:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Basic program balajee 2 2,815 Sep-11-2018, 07:19 PM
Last Post: gruntfutuk
  python!TypeError: can't multiply sequence by non-int of type 'float' shaywune 2 9,720 Sep-24-2016, 04:33 PM
Last Post: shaywune

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020