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
Last number code:
l = [] #initialising l with empty list
while True:
n = int(input()) #taking integer as an input
if n == 0: #if n is 0 exiting the loop
break
l.append(n) #adding elements to list l at the end
print(l[-1]) #-1 is the index of last element of list
Code Screenshot:
Output:
Middle digit code:
n = input() #taking number as a string
mid = len(n)//2 #calculating the mid position
print(n[mid]) #printing the middle digit
Code Screenshot:
Output:
Consecutive same signs integers code:
n = int(input()) #taking number of integers to take as input
l = input().split()#taking spaced integers as string and splitting them by space
for i in range(n):
l[i] = int(l[i])#converting string to integer in list
flag = False #initially assuming there are no consecutive same signs
for i in range(n-1): #traversing upto last but one element index
if l[i]*l[i+1] > 0: #if current element and next element are of same signs
flag = True #then flag is turned to True
break
if flag == True: #if flag true then printing YES
print("YES")
else: #else NO
print("NO")
Code Screenshot:
Output:
Alexa code:
n = int(input()) #taking number of integers to take as input
l = input().split()#taking spaced integers as string and splitting them by space
for i in range(n):
l[i] = int(l[i])#converting string to integer in list
if l[i]<0: #if the integer is negative
l[i] *= -1 #mutliplying it with -1 to convert it to positive
print(l) #printing the list
Code Screenshot:
Output:
Each and everything is explained in the comment section of code.
Thank you! Hit like if you like my work.
I want this using while loop This using stringin python Use list or some thing in...
Plz i want answer these question using list in python programme. You are given two sequences of n integers: 21, 22, ...,an and b1,b2, ..., bn Print a sequence of 2n integers created by alternating elements from the given sequences: a1, 61, 42, 62, a3, 63, ..., an, bn. Input The first line contains a positive integer n (1 <n<1000) - the length of the sequences The second line contains n space-separated integers 01, 02, ..., an (-1000 <a; <...
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 =...
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 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 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 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,...
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)...
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,...
write the solution of the program by python 3 language : I need the program using list : Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard....
9. [10 points) Consider the following algorithm: procedure Algorithm(n: positive integer; ddd: distinet integers) for k:=1 to n-1 for 1-1 to n-k print(k, I, di,da...-1,dn) if ds dti then interchange dy and d (a) Assume that this algorithm receives as input the integer n 6 and the input sequence 하하하하하하, Miss ^-ruteae rehen i12|3141516 Fill out the table below: ds ds (b) Assume that the algorithm receives the same input values as in part a). Once the algorithm finishes, what...