Lab Exam 2
Lab Exam 2
1. Write a Python program that takes a number, Z and prints how many even digits are in
that number. Then print the sum of the odd digits in the number Z. For example, if Z =
5218, then there are two odd digits in Z and the sum of even digits is : 5+1=6
Input Output
81 Odd Digits: 1
Sum: 1
64 Odd Digits: 0
Sum: 0
2. Write a program that takes a string as input and checks if it is a valid hexadecimal
number. A valid hexadecimal number contains only the digits 0-9 and the letters a-f or
A-F. The program should print “A hexadecimal number” if the string meets these criteria.
Otherwise, it should print “Not a hexadecimal number”.
Input:
The input consists of a single line containing a string S (1 ≤ length(S) ≤ 1000). This string
represents the sequence of characters to be checked.
Output:
The output should be a single line. If the string S contains only valid hexadecimal digits
(0-9, a-f, A-F), print “A hexadecimal number”. Otherwise, print “Not a hexadecimal
number”.
Input Output
Input
A single line containing a string S (1 ≤ length(S) ≤ 1000). The string will contain
upper case and lower case characters, and space.
Output
For each unique character (case-insensitive) in the string, print the character followed by
a colon and its frequency, each on a new line. Don’t print the frequency of space.
Input Output
ApPle a: 1
p: 2
l: 1
e: 1
Banana b: 1
a: 3
n: 2
Hello World h: 1
e: 1
l: 3
o: 2
w: 1
r: 1
d: 1
Explanation
In the third example, the string "Hello World" includes a space, which is ignored, and
only the frequencies of the non-whitespace characters are printed.
4. You are given an array A of N integers. Find and print the maximum element in the array
and its index (0-based).
Input:
The first line of input contains one integer N (1 ≤ N ≤ 1000), indicating the number of
elements in the array.
The second line contains N integers separated by spaces.
Output:
Print the maximum element.
Print the index (0-based) of the maximum element on a new line.
Input Output
5 Max element: 5
31415 The position is: 4
3 Max element: -1
-1 -2 -3 The position is: 0
4 Max element: 9
7912 The position is: 1
5. Write a program that asks the user to enter N numbers and print the maximum and
minimum of these N numbers. Next, find the sum of the even numbers among those N
numbers. See the sample output for better understanding.
Input:
The first line of input should be an integer N (where 1<=N < 10000), indicating the total
number of values the user will input.
Following the first line, there should be N lines, each containing an integer number X
(-10^7 < X < 10^7).
Input Output
5 Maximum number: 11
10 Minimum number: -7
11 Sum of even numbers: 18
8
-7
3
Output:
Print the output in the below format.