Chapter 6: Introduction to Python
Checkpoint (Pg. 99)
Fill in the blanks.
1. Guido van Rossum
2. interpreted
3. portable
4. interpreter, compiler
Exercises (Pgs. 113-115)
A. Tick (✓) the correct answers.
1. b
2. b
3. b
4. c
5. b
B. Fill in the blanks.
1. number
2. line by line
3. Script
4. editor
5. assignment
C. Write T for True and F for False.
1. F
2. T
3. F
4. T
5. T
A. Answer the following questions in short.
Q.1 What is Python?
Ans:- Python is a simple programming language used to create games, apps, and websites.
Q.2 What is a variable?
Ans:- A variable stores data like numbers or text, which can change during program execution.
Q.3 What is a string?
Ans:- A string is a group of characters written inside quotes, like "Hello" .
Q.4 What is an integer?
Ans:- An integer is a whole number without decimals, like 1, 10, or 100.
B. Answer the following questions in long.
Q.1 What is the role of an interpreter in Python ?
Ans:- An interpreter reads and executes a program line by line. It translates each statement into machine code as the program runs. This means that when you are writing a program in Python, the interpreter immediately processes each instruction one at a time and executes it. If there is an error in the code, the interpreter stops and shows you where the problem is. This makes it easier to find and fix mistakes as you go along.
Q.2 What are the key difference between Python's interactive mode and script mode ?
Ans:- Python has two main modes in which you can write and run your code:
Interactive Mode:- In this mode, Python processes each command or statement as soon as you press the Enter key. It is great for testing small pieces of code and getting immediate results.
Script Mode:- This is used for writing larger programs. A Python script is a collection of commands saved in a file. Once you have written your entire program, you can run it all at once as a single unit.
Q.3 What are the common data types in Python ?
Ans:- In Python, you can use the following basic data types:
Numeric Data Types: These types are used to represent numbers. Python supports two main types of numeric data:
• Integer (int): This data type stores whole numbers. The range of integer values is large, from -2,147,483,648 to 2,147,483,647.
• Floating-point (float): This data type stores decimal numbers, or numbers with a fractional part.
Boolean (bool): This data type is used to represent logical values. It can hold one of two values: True or False. In Python, 1 represents True and 0 represents False.
String (str): A string is a sequence of characters enclosed in either single quotes (‘) or double quotes (“). Strings are used to represent text.
Q.4 What is the purpose of the print() function in Python ?
Ans:- The print( ) function in Python is used to display messages, values, or results of commands on the screen. It is a commonly used function especially when you want to show the output of a program.
Q.5 What is a variable in Python , and how is it used ?
Ans:- In Python, a variable is a named storage that holds data for use in a program. It acts like a container for values such as numbers or text. Variables are assigned using the = operator, and each can store only one value at a time, which updates when reassigned.
Python Programs
1. Add Two Numbers
num1 = 1
num2 = 6
sum = num1 + num2
print('The sum of two number is ', sum)
2. Add the Numbers with User Input
num1 = input('Enter first number')
num2 = input('Enter second number')
Sum = float(num1) + float(num2)
print('the sum of two number is', sum)
a = int(input("Enter your number"))
if (a < 9) :
print("this is single digit number")
else :
print("this is double digit number")
Output
Enter your number - 2
This is single digit number
7. Print your name and class
print ("Ayushi Bharti")
print ("class-7")
Output
Ayushi Bharti
class-7
8. Add Two Strings
fname = "Ayushi"
sname = "Bharti"
Tname = fname + " " + sname
print (Tname)
Output
Ayushi Bharti
9. Print any string in Uppercase by user Input.
text = input ("Enter a string: ")
print ("Uppercase: ", text.upper())
Output
Enter a string: ayushi
AYUSHI
10. Print any string in lowercase by user Input.
text = input("Enter a string :")
print("lowercase :",text.lower())
Output
Enter a string : AYUSHI
ayushi
11. Make a grading system using python program.
Marks = Int(input("enter your marks"))
if (Marks >= 90):
print("Grade A+")
elif (Marks >= 75):
print("Grade A")
elif (Marks >= 60):
print("Grade B")
elif (Marks >= 40):
print("Grade C")
else:
print("fail")
Output
Enter your marks 90
Grade A+
Multiply a string by user input
a = input("Enter your name")
z = a * 2
print(z)
Output
Enter your name Ayushi
AyushiAyushiAyushi
No comments:
Write CommentsPlease ask any question about gk related