Python Questions
Python Questions
Given a triangle ABC which is right angled at B, and M is the midpoint of AC. Now, join B and M and find
the angle MBC with AB and BC given as inputs
Example:
Input Format
Output Format
Output
in degrees.
Examples:
10
10
Sample Output
45°
Solution:
import math
# Input
AB = float(input())
BC = float(input())
# Convert the angle from radians to degrees and round it to the nearest integer
angle_MBC_degrees = round(math.degrees(angle_MBC))
print(str(angle_MBC_degrees) + '°')
Easy 1:
Given first name and last name, you need to capitalize the first letter of the first name and last name
and insert it into the sentence "My name is First name Last name.".
Input Format
Constraints
Note: in a word only the first character is capitalized. Example 12abc when capitalized remains 12abc.
Output Format
Sample Input
chris alan
Sample Output
# Input
full_name = input()
# Split the full name into first name and last name
# Capitalize the first letter of the first name and last name
first_name = first_name.capitalize()
last_name = last_name.capitalize()
print(output_sentence)
Easy 2:
Given Marks of the students and a name as inputs.Print the average of the marks array for the student
name provided, showing 2 places after the decimal.
Input Format
The first line contains the integer, the number of students' records. The next lines contain the names
and marks obtained by a student, each value separated by a space. The final line contains query_name,
the name of a student to query.
Output Format
Print one line: The average of the marks obtained by the particular student correct to 2 decimal places.
Sample Input 0
Krishna 67 68 69
Arjun 70 98 63
Malika 52 56 60
Malika
Sample Output 0
56.00
Solution:
n = int(input())
student_marks = {}
# Input the student names and marks and store them in the dictionary
for _ in range(n):
line = input().split()
name = line[0]
student_marks[name] = marks
query_name = input()
print("{:.2f}".format(average_marks))
Given string will contain a first name, last name, and an id. Spaces in the string can be separated by any
number of zeros. And the Id will not contain any zero. Print the first name, last name and Id in a
dictionary.
Input Format
Output Format
Sample Input
Robert000Smith000123
Sample Output 0
Solution:
import re
input_string = input()
# Use regular expressions to extract the first name, last name, and ID
result = {
"first_name": match.group(1),
"last_name": match.group(2),
"id": match.group(3)
print(result)