0% found this document useful (0 votes)
18 views

Python Questions

The document describes a problem to calculate the angle MBC of a right triangle given the lengths of sides AB and BC. It provides sample input/output and code to calculate the angle in radians, convert it to degrees and round to the nearest integer. The code uses math functions like atan, degrees and round.

Uploaded by

supreet
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Python Questions

The document describes a problem to calculate the angle MBC of a right triangle given the lengths of sides AB and BC. It provides sample input/output and code to calculate the angle in radians, convert it to degrees and round to the nearest integer. The code uses math functions like atan, degrees and round.

Uploaded by

supreet
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Medium 2:

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

The first line contains the length of side AB.

The second line contains the length of side BC.

Output Format

Output

in degrees.

Note: Round the angle to the nearest integer.

Examples:

If angle is 56.5000001°, then output 57°.

If angle is 56.5000000°, then output 57°.

If angle is 56.4999999°, then output 56°.


Sample Input

10

10

Sample Output

45°

Solution:

import math

# Input

AB = float(input())

BC = float(input())

# Calculate the angle MBC in radians using the arctan function

angle_MBC = math.atan(AB / BC)

# Convert the angle from radians to degrees and round it to the nearest integer

angle_MBC_degrees = round(math.degrees(angle_MBC))

# Output the result

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

A single line of input containing the full name.

Constraints

The string consists of alphanumeric characters and spaces.

Note: in a word only the first character is capitalized. Example 12abc when capitalized remains 12abc.

Output Format

Print the capitalized string in the sentence.

Sample Input

chris alan

Sample Output

My name is Chris Alan.


Solution:

# Input

full_name = input()

# Split the full name into first name and last name

first_name, last_name = full_name.split()

# Capitalize the first letter of the first name and last name

first_name = first_name.capitalize()

last_name = last_name.capitalize()

# Create the output sentence

output_sentence = f"My name is {first_name} {last_name}."

# Output the result

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:

# Input the number of students' records

n = int(input())

# Create a dictionary to store student names and their respective marks

student_marks = {}

# Input the student names and marks and store them in the dictionary

for _ in range(n):

line = input().split()
name = line[0]

marks = list(map(float, line[1:]))

student_marks[name] = marks

# Input the student name to query

query_name = input()

# Calculate the average marks for the specified student

average_marks = sum(student_marks[query_name]) / len(student_marks[query_name])

# Print the result with 2 decimal places

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

The first line contains the string.

Output Format

Print the dictionary {"first_name": "", "last_name": "", "id": ""}

Sample Input
Robert000Smith000123

Sample Output 0

{"first_name": "Robert", "last_name": "Smith", "id": "123"}

Solution:

import re

# Input the string

input_string = input()

# Use regular expressions to extract the first name, last name, and ID

match = re.match(r"(\D+)0*(\D+)0*(\d+)", input_string)

# Create a dictionary with the extracted values

result = {

"first_name": match.group(1),

"last_name": match.group(2),

"id": match.group(3)

# Print the dictionary

print(result)

You might also like