Question

You are given two sequences of n integers: 21, 22, ...,an and b1,b2, ..., bn Print a sequence of 2n integers created by alter

You are given a sequence of n integers 21, 22, ..., Print elements of the sequence with even indices: a2, 24,... Input The fi

You are given a sequence of n positive integers 21, 22, ..., an Print elements of the sequence that are even. Input The first

You are given a sequence of n integers 21, 22, ..., an and an integer b. Increase each element of the sequence by b and print

Plz i want answer these question using list in python programme.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

> Print a sequence of 2n intergers created by alternatin elements from the given sequences:

CODE:

length = int(input()) #array length input
#Since values are given in one line, we have to split and store it in list
aList = [x for x in input().split()] #aList to store a1,a2,a3,...
bList = [x for x in input().split()] #bList to store b1,b2,b3,...

#Looping upto given length
for i in range(length):
   print(aList[i]) #Accessing the aList ith index and displaying
   print(bList[i]) #Accessing the bList ith index and displaying

CODE SCREENSHOT:

OUTPUT SCREENSHOT:

> Print elements of the sequence with even indices: a2,a4

CODE:

length = int(input()) #array length input
aList = [x for x in input().split()]#aList to store a1,a2,a3,...

for i in range(length): #Looping through aList
   #Since it is zero based indexing, so we have to identify an odd index
   if(i%2==1): #If i not divisible by 2, means odd index i.e even element
       print(aList[i]) #Accessing the aList ith index and displaying

CODE SCREENSHOT:

OUTPUT SCREENSHOT:

> print elements of the sequence that are even

CODE:

length = int(input()) #array length input
aList = [x for x in input().split()]#aList to store a1,a2,a3,...

for i in range(length): #Looping through aList
   if(int(aList[i])%2==0): #If aList[i] is divisible by 2, means it is even
       print(aList[i]) #displaying the val

CODE SCREENSHOT:

OUTPUT SCREENSHOT:

> Increase each element of the sequence by b and print the resulting sequence

CODE:

length = int(input()) #array length input
aList = [x for x in input().split()]#aList to store a1,a2,a3,...
b = int(input())

newList = [] #To store our new values
for i in range(length): #Looping through list
   newList.append(int(aList[i]) + b) #Appending our (aList[i] + b) to newList

for i in newList:#Loop through newList
   print(i) #Displaying the each element of newList

CODE SCREENSHOT:

OUTPUT SCREENSHOT:

Hope this will help you. Let me know, still if you have any queries..

Please rate the answer if you like it. Thanks.

Add a comment
Know the answer?
Add Answer to:
Plz i want answer these question using list in python programme. You are given two sequences...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I want this using while loop This using stringin python Use list or some thing in...

    I want this using while loop This using stringin python Use list or some thing in python Using list in python I want answer as soon as posdible E. Last Number time limit per test: 1 second memory limit per test: 256 megabytes input standard input output standard output You are given a sequence of positive integers aj, , 03, ... Print the last element of the sequence. Input The input consists of multiple lines. The i-th line contains a...

  • write the solution of the program by python 3 language : I need the program using...

    write the solution of the program by python 3 language : I need the program using list : You are given a sequence of n positive integers a1,a2,…,an, where n is even. Swap adjacent elements in the given sequence and print the resulting sequence: a2,a1,a4,a3,a6,a5,… Input The first line contains a positive even integer n (2≤n≤1000) — the length of the sequence. The second line contains n space-separated integers a1,a2,…,an (1≤ai≤1000) — the elements of the sequence. Output Print n...

  • write the solution of the program by python 3 language : I need the program using...

    write the solution of the program by python 3 language : I need the program using list or string or loops (while and for) or if,elif,else : You are given a sequence of n non-zero integers a1,a2,…,an. Determine if the given sequence contains a pair of adjacent elements of the same sign (both negative or both positive). Two elements are called adjacent if they stand next to each other in the sequence. Input The first line contains an integer n...

  • write the solution of the program by python 3 language : I need the program using...

    write the solution of the program by python 3 language : I need the program using list : You are given a non-decreasing sequence of n positive integers a1,a2,…,an. Print the number of distinct values in the sequence. For example, if the sequence is 1,2,2,2,3,4,4,5,7,10, the answer is 6 since distinct values are 1,2,3,4,5,7,10. Input The first line contains a positive integer n (1≤n≤1000) — the length of the sequence. The second line contains n space-separated positive integers a1,a2,…,an (1≤ai≤1000)...

  • write the solution of the program by python 3 language : I need the program using...

    write the solution of the program by python 3 language : I need the program using list or string or loops (while and for) or if,elif,else : i have 15 min to submit the solution please help me   You are given a sequence of n non-zero integers a1,a2,…,an. Determine if the given sequence contains a pair of adjacent elements of the same sign (both negative or both positive). Two elements are called adjacent if they stand next to each other...

  • write the solution of the program by python 3 language : I need the program using...

    write the solution of the program by python 3 language : I need the program using list or string or loops (while and for) or if,elif,else : Alex got a sequence of n integers a1,a2,…,an as a birthday present. Alex doesn't like negative numbers, so he decided to erase the minus signs from all negative numbers. As a result, he got a sequence of non-negative numbers. Print the resulting sequence. For example, if the sequence is  1, 5, -3, 4,...

  • Iwant answer this using number. Airthemitics. Varibles by python This using if else in python The...

    Iwant answer this using number. Airthemitics. Varibles by python This using if else in python The third picture using if. Elif. Else This using for loop in python A. Perimeter of a Rectangle time limit per test 1 second memory limit per test: 256 megabytes input standard input output standard output You are given two positive integers a and b which are the sides of the rectangle. Print the perimeter of this rectangle. The formula for perimeter is P =...

  • Java problem In this problem, the first input is a positive integer called n that will...

    Java problem In this problem, the first input is a positive integer called n that will represent the number of lines to process. The lines to be processed have one or more integers separated by whitespaces. For each of these lines, you must output: The minimum value of the integers The maximum value of the integers The sum of the integers It is worth to mention that the number of integers of each line is not known a priori and...

  • C programming question please meet all of the following conditions don't just output the same answer ​​​​​​​ Given a...

    C programming question please meet all of the following conditions don't just output the same answer ​​​​​​​ Given a sequence a. The elements of a has the following infomations: index The index is followed by the input order, starts from 1. The input won't contain index , you have to record it yourself. Smaller input index has higher priority. admin level : Level starts from 0 to 999. level 0 has the highest priority, while level 999 has the lowest....

  • Complete the Python program below that performs the following operations. First prompt the user to input...

    Complete the Python program below that performs the following operations. First prompt the user to input two integers, n and m. If n<m, then print the odd positive integers that are less than m (in order, on a single line, separated by spaces). If man, then print the even positive integers that are less than n (in order, on a single line, separated by spaces). If neem, then print nothing. For instance, if the user enters 5 followed by 10,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT