Python Programs

 Take input continiously

X =  list(map(int,input().split()))

# Python program showing how to
# multiple input using split
 
# taking two inputs at a time
x, y = input("Enter two values: ").split()
print("Number of boys: ", x)
print("Number of girls: ", y)
print()
 
# taking three inputs at a time
x, y, z = input("Enter three values: ").split()
print("Total number of students: ", x)
print("Number of boys is : ", y)
print("Number of girls is : ", z)
print()
 
# taking two inputs at a time
a, b = input("Enter two values: ").split()
print("First number is {} and second number is {}".format(a, b))
print()
 
# taking multiple inputs at a time
# and type casting using list() function
x = list(map(int, input("Enter multiple values: ").split()))
print("List of students: ", x)

Q1. Max and Min of an Array


Input 1:

5 1 2 3 4 5

Input 2:

4 10 50 40 80
Example Output

Output 1:

5 1

Output 2:

80 10
def main():
    # YOUR CODE GOES HERE
    # Please take input and print output to standard input/output (stdin/stdout)
    # E.g. 'input()/raw_input()' for input & 'print' for output

    x = list(map(int, input().split()))
    b = x[1:]
    print(max(b),min(b))

    return 0

if __name__ == '__main__':
    main()

Q3. Max and Min of an ArraySolved

Problem Description

Write a program to print maximum and minimum elements of the input array A of size N where you have to take integer N and other N elements as input from the user.



Problem Constraints

1 <= N <= 1000

1 <= A <= 1000



Input Format

A single line representing N followed by N integers of the array A



Output Format

A single line containing two space separated integers representing maximum and minimum elements of the input array.



Example Input

Input 1:

5 1 2 3 4 5

Input 2:

4 10 50 40 80



Example Output

Output 1:

5 1

Output 2:

80 10
def main():
    # YOUR CODE GOES HERE
    # Please take input and print output to standard input/output (stdin/stdout)
    # E.g. 'input()/raw_input()' for input & 'print' for output

    x = list(map(int, input().split()))
    b = x[1:]
    print(max(b),min(b))

    return 0

if __name__ == '__main__':
    main()

Comments

Popular posts from this blog

Pandas