Practice Questions — Introduction to Python
← Back to NotesTopic-Specific Questions
Question 1
Easy
Who created the Python programming language?
He is a Dutch programmer who started the project during Christmas holidays in 1989.
Python was created by Guido van Rossum.
Question 2
Easy
In which year was Python first released?
It was in the early 1990s.
Python was first released in 1991.
Question 3
Easy
Where does the name "Python" come from?
It is not named after the snake. Think of a British comedy show.
Python is named after the British comedy show "Monty Python's Flying Circus", which Guido van Rossum was a fan of.
Question 4
Easy
What does it mean when we say Python is an "interpreted" language?
Think about how the Python interpreter reads your code. Does it read everything at once or one line at a time?
An interpreted language is one where the code is executed line by line by an interpreter, rather than being converted into machine code all at once by a compiler.
Question 5
Easy
Is Python free to use? What term describes this kind of software?
The term means the source code is publicly available and anyone can use it.
Yes, Python is completely free. It is called open-source software.
Question 6
Easy
What file extension do Python files use?
It is a two-letter extension that comes from the first two letters of the language name.
Python files use the .py extension (for example,
hello.py).Question 7
Medium
What does "high-level language" mean? Give an example of a low-level language.
Think about which is easier for humans to read and write.
A high-level language is a programming language that is closer to human language and farther from machine language. It abstracts away the complex details of the computer hardware. An example of a low-level language is Assembly language.
Question 8
Medium
Name any three areas (fields) where Python is used in the real world.
Think about websites, data, intelligence, and games.
Python is used in (any three of the following): web development, data science, artificial intelligence and machine learning, game development, automation and scripting, scientific computing, and desktop applications.
Question 9
Medium
What is REPL? What does each letter stand for?
It has four words. The first is Read, the last is Loop.
REPL stands for Read-Eval-Print-Loop. It is Python's interactive shell where you type commands and see results immediately.
Question 10
Medium
What is the difference between an interpreter and a compiler?
Think about when the translation happens — all at once or one line at a time.
An interpreter translates and executes code one line at a time. A compiler translates the entire program into machine code first, and then the program is executed.
Question 11
Easy
Write a Python program that prints your name. For example, if your name is Priya, the output should be: My name is Priya.
Use the print() function with your name inside quotes.
print("My name is Priya.")Question 12
Medium
Write a Python program that prints the following three lines:
Line 1: I am learning Python.
Line 2: Python was created in 1991.
Line 3: It is a great language!
Line 1: I am learning Python.
Line 2: Python was created in 1991.
Line 3: It is a great language!
Use three separate print() statements, one for each line.
print("I am learning Python.")
print("Python was created in 1991.")
print("It is a great language!")Question 13
Medium
Name any two companies that use Python and explain what they use it for.
Think of a video streaming platform and a social media app.
Netflix uses Python for its recommendation engine and data analysis. Instagram uses Python (Django framework) for its entire backend.
Question 14
Medium
Why is Python considered easier to learn than Java or C++?
Compare how many lines of code you need to write a simple "Hello World" program.
Python is easier because it has simpler, cleaner syntax that reads like English. A "Hello World" program takes just one line in Python (
print("Hello, World!")) compared to 5-6 lines in Java or C++.Question 15
Hard
What is the difference between Python 2 and Python 3? Why should you use Python 3?
Think about support dates and compatibility.
Python 3 is the current and actively maintained version. Python 2 reached its end of life on January 1, 2020, meaning it no longer receives updates, security patches, or bug fixes. Python 3 has improved syntax (like
print() as a function), better Unicode support, and many new features.Question 16
Hard
Explain what "general-purpose" means when describing Python. How is it different from a "domain-specific" language?
General-purpose means it can do many types of tasks. A domain-specific language is designed for one specific area.
A general-purpose language like Python can be used for many different types of tasks — web development, data analysis, game development, automation, and more. A domain-specific language (DSL) is designed for one specific area. For example, SQL is only for database queries, and HTML is only for structuring web pages.
Question 17
Hard
If Python is an interpreted language and runs slower than compiled languages like C++, why do so many companies still choose Python?
Speed of the program is not always the most important factor. Think about development speed and team productivity.
Companies choose Python because developer productivity is often more important than program execution speed. Python allows developers to write code faster, read it more easily, and maintain it with less effort. For tasks where speed is critical, Python can use C/C++ extensions or specialized libraries like NumPy that run computationally intensive parts in compiled code.
Question 18
Hard
What was the ABC language, and how did it influence the creation of Python?
Guido van Rossum worked on ABC before Python. Think about what ABC did well and where it fell short.
ABC was a programming language developed at CWI in the Netherlands. It was designed to be easy to teach and use. Guido van Rossum worked on the ABC project and was inspired by its simplicity and readability. However, ABC had limitations — it was not extensible (you could not add new features easily) and was not suitable for real-world tasks. Python was created to keep ABC's readability while adding the flexibility and power needed for practical programming.
Question 19
Hard
What is open-source software? Name two advantages and one potential disadvantage of software being open-source.
Think about cost, community, and who is responsible for fixing bugs.
Open-source software is software whose source code is publicly available for anyone to view, use, modify, and distribute. Advantages: (1) It is free to use, removing financial barriers, and (2) a large community of developers can contribute to improving it, finding bugs, and adding features. Potential disadvantage: There is no single company responsible for guaranteed support — if you encounter a problem, you rely on the community for help rather than a dedicated support team.
Mixed & Application Questions
Question 1
Easy
What makes a programming language "beginner-friendly"? List at least three characteristics.
Think about how easy it is to read, how much setup is needed, and how quickly you can see results.
A beginner-friendly language has: (1) Simple, readable syntax that looks like natural language, (2) Minimal setup required to write and run your first program, (3) Quick feedback — you can see results immediately, (4) Good error messages that help you understand what went wrong, and (5) Large community with plenty of tutorials and help available.
Question 2
Medium
If you wanted to build a website using Python, which two frameworks could you use? Which one is more suitable for large projects?
One is "batteries included" and the other is lightweight.
The two major Python web frameworks are Django and Flask. Django is more suitable for large projects because it includes everything you need (authentication, database management, admin panel) built-in.
Question 3
Medium
Compare writing a "Hello World" program in Python with how you would describe the task in plain English. What do you notice?
The Python code is very close to the English instruction.
In plain English, you might say: "Print the text Hello World on the screen." In Python, you write:
print("Hello, World!"). The Python code is remarkably close to the English instruction — it uses the word print and puts the text in quotes. This closeness to natural language is what makes Python a "high-level" language.Question 4
Easy
What is a programming language? Explain in your own words.
Think of it as a way to talk to a computer, similar to how you use Hindi or English to talk to people.
A programming language is a set of rules and instructions that allows humans to communicate with computers. Just like we use natural languages (English, Hindi) to communicate with each other, we use programming languages to tell computers what tasks to perform.
Question 5
Medium
Name three Python libraries and the fields they are used in.
Think about data analysis, machine learning, and game development.
(Any three) pandas — data science and data analysis, TensorFlow — artificial intelligence and deep learning, Pygame — game development, NumPy — scientific computing and mathematics, Django — web development, Flask — web development, Matplotlib — data visualization.
Question 6
Hard
Imagine you are explaining to a friend why they should learn programming. They ask: "But I am not good at maths. Can I still learn to code?" What would you tell them?
Programming is more about logic and problem-solving than advanced mathematics.
You do not need to be good at advanced mathematics to learn programming. Programming is primarily about logical thinking, problem-solving, and giving clear instructions. Basic arithmetic (addition, subtraction, multiplication, division) is enough to get started. The maths skills you need will develop naturally as you learn to code.
Question 7
Medium
What is the difference between a text editor and an IDE? Which would you recommend for a beginner learning Python?
An IDE has more features built in, like running code, debugging, and autocomplete.
A text editor (like Notepad, Sublime Text) is a simple tool for writing text and code. An IDE (Integrated Development Environment, like VS Code, PyCharm, Thonny) provides additional features like code highlighting, auto-completion, debugging tools, and the ability to run code with one click. For beginners, Thonny or VS Code is recommended.
Question 8
Hard
Why do you think Python became more popular than other beginner-friendly languages like Scratch or Logo?
Think about what happens after learning the basics. Can you build real projects with Scratch?
While Scratch and Logo are excellent for introducing very young children to programming concepts, they are limited in what you can build with them. Python is beginner-friendly AND powerful enough for professional use. You can start learning with simple print statements and eventually build real websites, data analysis tools, AI models, and professional software — all in the same language.
Question 9
Easy
Write a Python program that prints the result of multiplying 12 by 15.
Use the print() function with the multiplication operator (*).
print(12 * 15)
Output: 180Question 10
Medium
What would happen if Python were a compiled language instead of an interpreted language? How would the development process change?
Think about the extra step needed before running code and what happens when there is an error.
If Python were compiled, you would need to compile the entire program before running it. Every time you made a change, you would have to recompile. If there were any errors anywhere in the code, the entire compilation would fail and nothing would run. The REPL would not exist because there would be no line-by-line execution.
Question 11
Hard
Research question: Find out what the "Zen of Python" is. How do you display it in the Python REPL? Name any three of its principles.
There is a special command you can type in the Python REPL. It starts with 'import'.
The Zen of Python is a collection of 19 guiding principles for writing Python code. You display it by typing
import this in the Python REPL. Three principles include: (1) "Beautiful is better than ugly", (2) "Simple is better than complex", (3) "Readability counts".Question 12
Hard
Python is dynamically typed, while Java is statically typed. Without knowing these terms yet, based on what you have learned about Python's design philosophy, which approach do you think Python would prefer and why?
Python's design philosophy favors simplicity and less code. Which approach sounds simpler?
Python prefers dynamic typing, meaning you do not have to declare the type of a variable when you create it. This aligns with Python's philosophy of keeping code simple and readable. In Java (static typing), you must specify whether a variable holds a number, text, or other type before using it.
Multiple Choice Questions
MCQ 1
Who created the Python programming language?
Answer: B
B is correct. Guido van Rossum created Python in 1991. Dennis Ritchie created the C programming language. James Gosling created Java. Bjarne Stroustrup created C++.
B is correct. Guido van Rossum created Python in 1991. Dennis Ritchie created the C programming language. James Gosling created Java. Bjarne Stroustrup created C++.
MCQ 2
In which year was Python first released?
Answer: B
B is correct. Python was first released in February 1991. 1989 is when Guido van Rossum started working on it (during Christmas holidays), but it was not released until 1991. 1995 is when Java was released. 2000 is when Python 2.0 was released.
B is correct. Python was first released in February 1991. 1989 is when Guido van Rossum started working on it (during Christmas holidays), but it was not released until 1991. 1995 is when Java was released. 2000 is when Python 2.0 was released.
MCQ 3
Python is named after:
Answer: C
C is correct. Python is named after the British comedy show "Monty Python's Flying Circus". Although the Python logo features intertwined snakes, the language name comes from the comedy show. It is not named after a Greek god or a Dutch city.
C is correct. Python is named after the British comedy show "Monty Python's Flying Circus". Although the Python logo features intertwined snakes, the language name comes from the comedy show. It is not named after a Greek god or a Dutch city.
MCQ 4
What type of language is Python?
Answer: B
B is correct. Python is an interpreted language — the interpreter reads and executes code one line at a time. A compiled language (like C++) requires the entire code to be converted to machine code before execution. Assembly language is a low-level language that uses mnemonics. Machine language is binary code (0s and 1s) that the CPU directly executes.
B is correct. Python is an interpreted language — the interpreter reads and executes code one line at a time. A compiled language (like C++) requires the entire code to be converted to machine code before execution. Assembly language is a low-level language that uses mnemonics. Machine language is binary code (0s and 1s) that the CPU directly executes.
MCQ 5
Which of the following is the correct way to print "Hello" in Python 3?
Answer: C
C is correct. In Python 3, print() is a function that requires parentheses. Option A (
C is correct. In Python 3, print() is a function that requires parentheses. Option A (
print "Hello") was valid in Python 2 but causes an error in Python 3. Option B (echo) is a command used in PHP and shell scripting, not Python. Option D (console.log) is used in JavaScript, not Python.MCQ 6
What file extension is used for Python source code files?
Answer: C
C is correct. Python files use the .py extension (for example, hello.py). The other extensions (.python, .pt, .pn) are not standard Python file extensions. The .pt extension is sometimes used for PyTorch model files, not source code.
C is correct. Python files use the .py extension (for example, hello.py). The other extensions (.python, .pt, .pn) are not standard Python file extensions. The .pt extension is sometimes used for PyTorch model files, not source code.
MCQ 7
What does REPL stand for?
Answer: B
B is correct. REPL stands for Read-Eval-Print-Loop. Read (reads input), Eval/Evaluate (evaluates the expression), Print (displays the result), Loop (repeats the process). Option A is close but uses 'Execute' instead of 'Eval'. Options C and D use incorrect terms.
B is correct. REPL stands for Read-Eval-Print-Loop. Read (reads input), Eval/Evaluate (evaluates the expression), Print (displays the result), Loop (repeats the process). Option A is close but uses 'Execute' instead of 'Eval'. Options C and D use incorrect terms.
MCQ 8
Which of the following is NOT a real use of Python?
Answer: C
C is correct. Python is NOT used for designing CPU hardware. Hardware design uses specialized languages like Verilog or VHDL. Python IS used for building websites (Django, Flask), analyzing data (pandas, NumPy), and creating AI models (TensorFlow, PyTorch).
C is correct. Python is NOT used for designing CPU hardware. Hardware design uses specialized languages like Verilog or VHDL. Python IS used for building websites (Django, Flask), analyzing data (pandas, NumPy), and creating AI models (TensorFlow, PyTorch).
MCQ 9
Which command opens the Python interactive shell in the terminal?
Answer: C
C is correct. You type
C is correct. You type
python (or python3 on some systems) in the terminal to open the interactive shell (REPL). Options A, B, and D are not valid commands for starting the Python interpreter.MCQ 10
Python is described as a "high-level" language. What does this mean?
Answer: B
B is correct. High-level means the language is closer to human language (English) and abstracts away the complex details of the hardware. Option A is wrong — Python runs on any computer. Option C is wrong — 'high-level' is a classification, not a quality ranking. Option D is wrong — high-level languages are often slower than low-level languages because of the abstraction.
B is correct. High-level means the language is closer to human language (English) and abstracts away the complex details of the hardware. Option A is wrong — Python runs on any computer. Option C is wrong — 'high-level' is a classification, not a quality ranking. Option D is wrong — high-level languages are often slower than low-level languages because of the abstraction.
MCQ 11
Which company's backend is built entirely using Python's Django framework?
Answer: C
C is correct. Instagram's entire backend is built with Python using the Django framework. Facebook primarily uses PHP (Hack). Twitter initially used Ruby on Rails and later moved to Scala and Java. Amazon primarily uses Java.
C is correct. Instagram's entire backend is built with Python using the Django framework. Facebook primarily uses PHP (Hack). Twitter initially used Ruby on Rails and later moved to Scala and Java. Amazon primarily uses Java.
MCQ 12
What happens when there is an error on line 5 of a Python program?
Answer: B
B is correct. Since Python is interpreted (line by line), lines 1-4 execute normally, and the program stops at line 5 when the error is encountered. Option A describes compiler behavior (where no lines run if there is an error). Option C is wrong — Python does not skip errors. Option D is wrong — Python reports errors but does not fix them automatically.
B is correct. Since Python is interpreted (line by line), lines 1-4 execute normally, and the program stops at line 5 when the error is encountered. Option A describes compiler behavior (where no lines run if there is an error). Option C is wrong — Python does not skip errors. Option D is wrong — Python reports errors but does not fix them automatically.
MCQ 13
Which of the following is a Python library used for data analysis?
Answer: B
B is correct. pandas is a Python library for data analysis and manipulation. React and Angular are JavaScript frameworks for building user interfaces. Bootstrap is a CSS framework for responsive web design. None of the other options are Python libraries.
B is correct. pandas is a Python library for data analysis and manipulation. React and Angular are JavaScript frameworks for building user interfaces. Bootstrap is a CSS framework for responsive web design. None of the other options are Python libraries.
MCQ 14
Which language inspired the creation of Python?
Answer: C
C is correct. Python was inspired by the ABC language, which Guido van Rossum worked on at CWI. ABC was designed to be easy to learn, and Python inherited this philosophy. C++ was created by Bjarne Stroustrup. Java was created after Python (1995). BASIC is an older teaching language that did not directly influence Python.
C is correct. Python was inspired by the ABC language, which Guido van Rossum worked on at CWI. ABC was designed to be easy to learn, and Python inherited this philosophy. C++ was created by Bjarne Stroustrup. Java was created after Python (1995). BASIC is an older teaching language that did not directly influence Python.
MCQ 15
When did Python 2 reach its end of life (no more updates or support)?
Answer: C
C is correct. Python 2 reached its end of life on January 1, 2020. After this date, Python 2 no longer receives any updates, security patches, or bug fixes. The other dates are incorrect — the end-of-life was originally planned for 2015 but was extended to 2020.
C is correct. Python 2 reached its end of life on January 1, 2020. After this date, Python 2 no longer receives any updates, security patches, or bug fixes. The other dates are incorrect — the end-of-life was originally planned for 2015 but was extended to 2020.
MCQ 16
Why does Python use an interpreter instead of a compiler?
Answer: C
C is correct. Python uses an interpreter because it allows developers to test code quickly, see results line by line, and use the interactive REPL. Option A is wrong — compilers existed long before Python. Option B is wrong — compiled code typically runs faster, not slower. Option D is wrong — Python code is simpler than most compiled languages.
C is correct. Python uses an interpreter because it allows developers to test code quickly, see results line by line, and use the interactive REPL. Option A is wrong — compilers existed long before Python. Option B is wrong — compiled code typically runs faster, not slower. Option D is wrong — Python code is simpler than most compiled languages.
MCQ 17
Which of the following statements about Python is FALSE?
Answer: C
C is the FALSE statement and therefore the correct answer. Python is an interpreted language — it does NOT need to be compiled before running. The interpreter executes code line by line. Options A, B, and D are all true statements about Python.
C is the FALSE statement and therefore the correct answer. Python is an interpreted language — it does NOT need to be compiled before running. The interpreter executes code line by line. Options A, B, and D are all true statements about Python.
MCQ 18
What is the output of typing 2 ** 10 in the Python REPL?
Answer: C
C is correct. The
C is correct. The
** operator in Python means 'to the power of'. So 2 ** 10 means 2 raised to the power of 10, which equals 1024 (2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2). Option A (20) would be 2 * 10. Option B (210) is just the digits combined. Option D (100) would be 10 ** 2.MCQ 19
Python is best described as:
Answer: B
B is correct. Python is high-level (close to human language), interpreted (runs line by line), and general-purpose (used for many different types of tasks). Every other option has at least one incorrect term. Python is NOT low-level, NOT compiled, and NOT domain-specific.
B is correct. Python is high-level (close to human language), interpreted (runs line by line), and general-purpose (used for many different types of tasks). Every other option has at least one incorrect term. Python is NOT low-level, NOT compiled, and NOT domain-specific.
MCQ 20
What will happen if you type Print("Hello") in Python? (Note the capital P)
Answer: C
C is correct. Python is case-sensitive, so
C is correct. Python is case-sensitive, so
Print and print are different names. Since Print (with capital P) is not defined anywhere, Python raises a NameError: name 'Print' is not defined. Option A is wrong because the capital P matters. Option B is wrong — Python does not auto-correct case. Option D is wrong — it is a NameError, not a SyntaxError.MCQ 21
Which of the following is NOT a feature that Python inherited from the ABC language?
Answer: C
C is correct. Object-oriented programming was NOT a feature of the ABC language. ABC focused on clean syntax, ease of learning, and interactive usage. Python added object-oriented programming (classes, inheritance) as one of its improvements over ABC, drawing inspiration from languages like C++ and Modula-3.
C is correct. Object-oriented programming was NOT a feature of the ABC language. ABC focused on clean syntax, ease of learning, and interactive usage. Python added object-oriented programming (classes, inheritance) as one of its improvements over ABC, drawing inspiration from languages like C++ and Modula-3.
MCQ 22
Which of the following Python frameworks is described as following the "batteries included" philosophy?
Answer: C
C is correct. Django follows the 'batteries included' philosophy, meaning it provides everything you need to build a web application (authentication, database management, admin panel, URL routing) out of the box. Flask is a lightweight micro-framework that does not include these by default. Pygame is for game development, not web development. NumPy is for numerical computing, not web development.
C is correct. Django follows the 'batteries included' philosophy, meaning it provides everything you need to build a web application (authentication, database management, admin panel, URL routing) out of the box. Flask is a lightweight micro-framework that does not include these by default. Pygame is for game development, not web development. NumPy is for numerical computing, not web development.
Coding Challenges
Challenge 1: Print Your Full Name
EasyWrite a Python program that prints your full name on one line. For example, if your name is Aarav Sharma, the output should be exactly: My name is Aarav Sharma.
Sample Input
(No input required)
Sample Output
My name is Aarav Sharma.
Use the print() function. The output must be exactly one line.
print("My name is Aarav Sharma.")Challenge 2: Draw a Box with Stars
EasyWrite a Python program that prints a rectangular box made of asterisk (*) characters. The box should be 5 characters wide and 4 lines tall, with hollow inside.
Sample Input
(No input required)
Sample Output
* * * * *
* *
* *
* * * * *
Use only print() statements. You should use exactly 4 print() statements.
print("* * * * *")
print("* *")
print("* *")
print("* * * * *")Challenge 3: Print a Short Poem
EasyWrite a Python program that prints the following 4-line poem (or any poem of your choice with at least 4 lines), with each line on a separate line of output.
Sample Input
(No input required)
Sample Output
Twinkle, twinkle, little star,
How I wonder what you are.
Up above the world so high,
Like a diamond in the sky.
Use separate print() statements for each line. Minimum 4 lines of output.
print("Twinkle, twinkle, little star,")
print("How I wonder what you are.")
print("Up above the world so high,")
print("Like a diamond in the sky.")Challenge 4: Calculator Challenge
MediumUse Python as a calculator to solve the following expression and print the result: (25 + 17) * 3. Do NOT calculate the answer yourself — let Python do the math.
Sample Input
(No input required)
Sample Output
126
You must use the mathematical expression inside the print() function. Do not hardcode the answer (do not write print(126)).
print((25 + 17) * 3)Challenge 5: Monday Timetable
MediumWrite a Python program that prints your school timetable for Monday in a formatted way. Include at least 5 periods with subject names and timings.
Sample Input
(No input required)
Sample Output
=== Monday Timetable ===
1. 08:00 - 08:45 Mathematics
2. 08:45 - 09:30 English
3. 09:30 - 10:15 Science
4. 10:30 - 11:15 Hindi
5. 11:15 - 12:00 Computer Science
Use print() statements. The timetable must be neatly formatted with at least 5 entries. Include a title line.
print("=== Monday Timetable ===")
print("1. 08:00 - 08:45 Mathematics")
print("2. 08:45 - 09:30 English")
print("3. 09:30 - 10:15 Science")
print("4. 10:30 - 11:15 Hindi")
print("5. 11:15 - 12:00 Computer Science")Challenge 6: Triangle Pattern
MediumWrite a Python program that prints the following right-angled triangle pattern using only print() statements and asterisk (*) characters.
Sample Input
(No input required)
Sample Output
*
* *
* * *
* * * *
* * * * *
Use exactly 5 print() statements, one for each row. Do not use loops (you have not learned them yet).
print("*")
print("* *")
print("* * *")
print("* * * *")
print("* * * * *")Challenge 7: Add Comments to a Program
MediumThe following program has no comments. Rewrite it with a comment above each line explaining what it does:
print("Welcome to Python!")
print(2 + 3)
print("Goodbye!")Sample Input
(No input required)
Sample Output
Welcome to Python!
5
Goodbye!
Add at least one comment (starting with #) before each print statement. The output should remain the same as the original program.
# Print a welcome message to the user
print("Welcome to Python!")
# Calculate and print the sum of 2 and 3
print(2 + 3)
# Print a farewell message
print("Goodbye!")Challenge 8: Multiplication Table for 7
HardWrite a Python program that prints the first 5 lines of the multiplication table for 7. Each line should show the multiplication expression and the result. Use Python to calculate the answers (do not hardcode them).
Sample Input
(No input required)
Sample Output
7 x 1 = 7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
Use print() with mathematical expressions. Do not calculate the answers yourself — let Python compute 7*1, 7*2, etc. You have not learned string formatting yet, so use separate print statements.
print("7 x 1 =", 7 * 1)
print("7 x 2 =", 7 * 2)
print("7 x 3 =", 7 * 3)
print("7 x 4 =", 7 * 4)
print("7 x 5 =", 7 * 5)Challenge 9: Personal Introduction Card
HardWrite a Python program that prints a neatly formatted personal introduction card inside a border. Include your name, age, city, favourite subject, and a fun fact about yourself.
Sample Input
(No input required)
Sample Output
+---------------------------+
| INTRODUCTION CARD |
+---------------------------+
| Name : Rohan Mehta |
| Age : 14 |
| City : Bangalore |
| Subject : Computer Science|
| Fun Fact: I love chess! |
+---------------------------+
Use print() statements to create the border and content. The card should have at least 5 fields of personal information. Try to align the content neatly.
print("+---------------------------+")
print("| INTRODUCTION CARD |")
print("+---------------------------+")
print("| Name : Rohan Mehta |")
print("| Age : 14 |")
print("| City : Bangalore |")
print("| Subject : Computer Science|")
print("| Fun Fact: I love chess! |")
print("+---------------------------+")Challenge 10: Mathematical Expressions Challenge
HardWrite a Python program that calculates and prints the results of ALL of the following expressions, each on a separate line with a label:
1. The sum of all numbers from 1 to 5 (1+2+3+4+5)
2. 2 raised to the power of 16
3. The remainder when 100 is divided by 7
4. Integer division of 100 by 7 (whole number result only)
5. The result of (15 + 5) * (10 - 3) / 2
1. The sum of all numbers from 1 to 5 (1+2+3+4+5)
2. 2 raised to the power of 16
3. The remainder when 100 is divided by 7
4. Integer division of 100 by 7 (whole number result only)
5. The result of (15 + 5) * (10 - 3) / 2
Sample Input
(No input required)
Sample Output
Sum of 1 to 5 = 15
2 to the power 16 = 65536
100 mod 7 = 2
100 divided by 7 (integer) = 14
Expression result = 70.0
Use Python operators to calculate each result. The % operator gives remainder, the // operator gives integer division, and ** gives exponentiation. Do not hardcode any answers.
print("Sum of 1 to 5 =", 1 + 2 + 3 + 4 + 5)
print("2 to the power 16 =", 2 ** 16)
print("100 mod 7 =", 100 % 7)
print("100 divided by 7 (integer) =", 100 // 7)
print("Expression result =", (15 + 5) * (10 - 3) / 2)Need to Review the Concepts?
Go back to the detailed notes for this chapter.
Read Chapter NotesWant to learn Python with a live mentor?
Explore our Python course