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

Lab 1, 2

The document outlines 14 exercises/tasks to practice programming fundamentals in Python. The exercises cover basic concepts like variable assignment, data types, arithmetic operations, string manipulation, user input, conditional logic, and loops. They involve declaring and assigning variables, performing calculations, accepting and validating user input, and printing output. The goal is to help learners practice and reinforce core programming skills.

Uploaded by

farahmaqbool644
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)
19 views

Lab 1, 2

The document outlines 14 exercises/tasks to practice programming fundamentals in Python. The exercises cover basic concepts like variable assignment, data types, arithmetic operations, string manipulation, user input, conditional logic, and loops. They involve declaring and assigning variables, performing calculations, accepting and validating user input, and printing output. The goal is to help learners practice and reinforce core programming skills.

Uploaded by

farahmaqbool644
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/ 2

Programming Fundamentals

Exercises
Exercise 1: Simple Variable Assignment

1. Declare a variable name and assign your name to it.


2. Declare a variable age and assign your age to it.
3. Print both variables in a readable format.

Exercise 2: Multiple Variable Assignments

1. Declare three variables: num1, num2, and result.


2. Assign integer values to num1 and num2.
3. Add num1 and num2 and store the result in the result variable.
4. Print the values of all three variables.

Exercise 3: Variable Types

1. Declare a variable price and assign a float value to it.


2. Declare a variable quantity and assign an integer value to it.
3. Calculate the total cost (price * quantity) and store it in a variable total_cost.
4. Print the values of all three variables.

Exercise 4: String Concatenation

1. Declare two string variables, first_name and last_name, and assign your first and last names.
2. Concatenate the two strings and store the result in a variable full_name.
3. Print the full_name variable.

Exercise 5: Boolean Variables

1. Declare a Boolean variable is_adult and assign True if you are above 18, otherwise False.
2. Print the value of the is_adult variable.

Exercise 6: Interactive User Input

1. Use the input() function to get the user's name.


2. Store the input in a variable called user_input.
3. Print a personalized greeting using the user_input.

Exercise 7: Temperature Conversion

1. Declare a variable celsius_temperature and assign a temperature in Celsius.


2. Convert the temperature to Fahrenheit using the formula: F = (C * 9/5) + 32.
3. Print the original Celsius temperature and the converted Fahrenheit temperature.

Exercise 8: Swapping Variables

1. Declare two variables, a and b, and assign values to them.


2. Swap the values of a and b without using a temporary variable.
3. Print the values of a and b after swapping.
Task 9: Calculator Program

1. Write a Python program that acts as a simple calculator.


2. It should take two numbers and an operator (+, -, *, /) as input from the user.
3. Perform the corresponding arithmetic operation and display the result.
4. Implement error handling to handle cases such as division by zero or invalid operators.

Task 10: Temperature Conversion

1. Create a Python program that converts temperatures between Celsius and Fahrenheit.
2. Prompt the user to enter a temperature and its unit (Celsius or Fahrenheit).
3. Convert the temperature to the other unit and display the result.
4. Allow the user to choose whether to perform another conversion.

Task 11: String Manipulation

1. Write a Python program that takes a user's full name as input.


2. Split the name into first and last names.
3. Display the first and last names separately.
4. Implement a feature to count and display the number of characters in the full name.

Task 12: List Operations

1. Create a Python program that operates on a list of numbers.


2. Allow the user to input a list of numbers (comma-separated).
3. Calculate and display the sum, average, and product of the numbers.
4. Implement error handling for invalid inputs.

Task 13: Logical Operations

1. Write a Python program that checks whether a given year is a leap year.
2. Prompt the user to enter a year.
3. Display whether the entered year is a leap year or not.
4. Implement additional checks, such as ensuring the user enters a positive integer.

Task 14: Pattern Printing

1. Create a Python program that prints a pattern using nested loops.


2. Allow the user to input the number of rows for the pattern.
3. Display a pattern, for example, a triangle or a square.
4. Implement error handling for non-integer inputs.

You might also like