EX 1 Exercise Programs
EX 1 Exercise Programs
Input:
Output:
10
20.5
Hello, World!
True
[1, 2, 3, 4, 5]
(6, 7, 8)
{'key1': 'value1', 'key2': 'value2'}
None
Integer: 10
Float: 20.5
String: Hello, World!
Boolean: True
List: [1, 2, 3, 4, 5]
Tuple: (6, 7, 8)
Dictionary: {'key1': 'value1', 'key2': 'value2'}
None: None
Integer: 10
Float: 20.5
String: Hello, World!
Boolean: True
List: [1, 2, 3, 4, 5]
Tuple: (6, 7, 8)
Dictionary: {'key1': 'value1', 'key2': 'value2'}
None: None
Integer: 10
Float: 20.5
String: Hello, World!
Boolean: True
List: [1, 2, 3, 4, 5]
Tuple: (6, 7, 8)
Dictionary: {'key1': 'value1', 'key2': 'value2'}
None: None
Input:
# Define a variable with an integer type
value = 42 # Integer
# Convert the variable to other data types and print the results
# Integer to float
float_value = float(value)
print(f"Integer to Float: {float_value}")
# Integer to string
string_value = str(value)
print(f"Integer to String: {string_value}")
3. Take input from the user his/her first name and last name and
display full name.
Input:
# Take input from the user for first name and last name
first_name = input("Enter your first name: ")
last_name = input("Enter your last name: ")
# Concatenate first name and last name to form the full name
full_name = first_name + " " + last_name
4. Take string from the user and find the length of the string .
Convert into all lower case and uppercase , first letter capital and
display the string.
Input:
# Take a string input from the user
user_string = input("Enter a string: ")
Output:
5.Take string from the user and display only first three character of
it.
Input:
Output:
6.Take string from the user and display last three character of it.
Input:
# Take a string input from the user
user_string = input("Enter a string: ")
Output:
Enter a string: My Name Is Priyank
The last three characters of the string are: ank
7. Split the string.
Input:
Output:
Enter a string: My Name Is Priyank
The split string is: ['My', 'Name', 'Is', 'Priyank']
8. Input the string and character from the user and find how many
times a particular character exists in the string.
Input:
# Take a string input from the user
user_string = input("Enter a string: ")
Output:
Enter a string: My Name Is Priyank
Enter a character to find: P
The character 'P' appears 1 time(s) in the string.
Input:
# Take a string input from the user
user_string = input("Enter a string: ")
Output: