[go: up one dir, main page]

0% found this document useful (0 votes)
16 views4 pages

Chap 1 Notes

Uploaded by

nanditha629
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views4 pages

Chap 1 Notes

Uploaded by

nanditha629
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Answer in One Word or a Sentence

1. When was Python language released? 1991


2. Name the literal used for defining decimal numbers. Float Literal
3. Name the mode in which instructions are executed line by line. Interactive mode
4. Which type of literal is used to represent the logical values? Boolean
5. Name the mode used to create and edit Python programs. Script
Part 3: Answer the Following:
1. Write any four features of Python language.
o Easy to Learn: Python is a simple and easy to learn and is a general-purpose
programming language.
o Simple structure- It has a simple structure, a few key words and a clearly defined
syntax.
o Free to use: It's free to use for commercial purposes. The source code of python
is available under the general public licence.
o Platform Independent: Python code can run on any operating systems like
Windows, macOS, and Linux without needing major changes and any machine.
2. What is a variable? Discuss the rules for naming a variable.
o What is a Variable? In Python, a variable is a named memory location that holds
data. When you create a variable, you give it a name, and then you can store
different types of values (like numbers, text, etc.) in it.
o Rules for Naming a Variable:
▪ Variable names must start with a letter (a-z, A-Z) or an underscore (_).
▪ The rest of the name can contain letters, digits (0-9), or underscores.
▪ Variable names are case-sensitive (e.g., age and Age are considered
different variables).
▪ Keywords (reserved words in Python like if, for, while, etc.) cannot be
used as variable names.
▪ No spaces are allowed in variable names.
3. Explain the different working modes of Python. Python primarily works in two modes:
o Interactive Mode (or Immediate Mode): In this mode, you type Python
commands one line at a time, and the Python interpreter immediately executes
them and shows the result. It's useful for testing small pieces of code or for quick
calculations. You'll typically see a >>> prompt.
o Script Mode (or Program Mode): In this mode, you write your Python code in a
file (usually with a .py extension) using a text editor or an Integrated
Development Environment (IDE). You save the file, and then you can run the
entire program at once. This mode is used for writing larger and more complex
programs.
4. Describe the significance of Script mode in Python.
5. Script mode is significant because it allows you to:
o Write and Save Complete Programs: You can write long and complex programs
and save them as files, which can be run multiple times without re-typing.
o Organize Code: It helps in organizing your code into logical blocks and functions,
making it easier to manage and debug.
o Reusability: Once a script is written, it can be executed whenever needed,
promoting code reusability.
o Collaboration: Multiple programmers can work on different parts of a large
project, saving their code in separate scripts.
6. What is the use of print() function? Explain with the help of an example.
o Use of print() function: The print() function in Python is used to display output
on the console or screen. It's how your Python program communicates results or
messages to the user.

Program to calculate the product of two numbers


x = 150
y = 200
product = x * y
print("The product of x and y is:", product)

Program to calculate average speed


# Given values for distance and time
distance_km = 192
time_hours = 3
average_speed = distance_km / time_hours
print("Distance covered:", distance_km, "km")
print("Time taken:", time_hours, "hours")
print("The average speed is:", average_speed, "km/h")

Program to calculate circumference and area of a circle


import math
radius = float(input("Enter the radius of the circle: "))
circumference = 2 * math.pi * radius
area = math.pi * (radius ** 2)
print("Radius:", radius)
print("Circumference:", circumference)
print("Area:", area)
Or

radius = 10
circumference = 2 * 22/7 * radius
area = 22/7 * (radius* radius)
print("Radius:", radius)
print("Circumference:", circumference)
print("Area:", area)

Program to calculate total marks and percentage of a student

# Input student details


roll_number = input("Enter student's Roll Number: ")
student_name = input("Enter student's Name: ")

# Input marks for five subjects.


print("\nEnter marks for five subjects (out of 100 each):")
sub1_marks = float(input("Marks in Subject 1: "))
sub2_marks = float(input("Marks in Subject 2: "))
sub3_marks = float(input("Marks in Subject 3: "))
sub4_marks = float(input("Marks in Subject 4: "))
sub5_marks = float(input("Marks in Subject 5: "))

# Calculate total marks obtained


total_marks_obtained = sub1_marks + sub2_marks + sub3_marks + sub4_marks + sub5_marks
maximum_marks = 5 * 100

# Calculate percentage
percentage = (total_marks_obtained / maximum_marks) * 100

# Display the results in a formatted way


print("\n--- Student Mark Sheet ---")
print("Roll Number:", roll_number)
print("Name:", student_name)
print("--------------------------")
print("Marks in Subject 1:", sub1_marks)
print("Marks in Subject 2:", sub2_marks)
print("Marks in Subject 3:", sub3_marks)
print("Marks in Subject 4:", sub4_marks)
print("Marks in Subject 5:", sub5_marks)
print("--------------------------")
print("Total Marks Obtained:", total_marks_obtained)
print("Percentage:", percentage)

You might also like