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

Lab1 Basic

This document contains a Python programming lab assignment on various Python data types including strings, numbers, Booleans, and user input. The lab covers string slicing, string immutability, numeric data types, Boolean values, multiple assignment, null values, and writing a program to swap two numbers input by the user. Questions are provided throughout with expected output answers. The goal of the lab is to practice working with different data types in Python.

Uploaded by

POKIN ONPHAN
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 views

Lab1 Basic

This document contains a Python programming lab assignment on various Python data types including strings, numbers, Booleans, and user input. The lab covers string slicing, string immutability, numeric data types, Boolean values, multiple assignment, null values, and writing a program to swap two numbers input by the user. Questions are provided throughout with expected output answers. The goal of the lab is to practice working with different data types in Python.

Uploaded by

POKIN ONPHAN
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/ 3

Python Programming for Data Science

Lab 1 Assignment

1. Strings
data = 'hello world' Q1.1 What is the letter of index 4 of data?
print(data[0]) Ans. O
print(len(data)) Q1.2 How is long of data?
print(data) Ans 11
print(type(data)) Q1.3 What is the data type of data?
Ans. string
1.1 Slicing: Slicing, in strings, refers to removing some part of a string.
name = 'Sonam' Q1.1.1 What is the output?
print(name) Ans. Sonam
name1=name[1:]
print(name1) onem

name = name[2:] mannam


name = "man" +name
print(name)
1.2 Immutability of Strings
name = 'Sonam' Q1.2.1 What is the output?
Son am
print(name) Ans.
man nam
name = name[2:] Q1.2.2 Compare the result to 1.1.
name = 'man' +name Ans. no
printOnam
print(name)

2. Numbers
value = 123.1 Q2.1 What is output of first print?
print(value) Ans. 123-1
print(type(value)) Q2.2 What is data type of first print?
value = 10 Ans. float
print(value) Q2.3 What is output of second print?
print(type(value)) Ans. 10
Q2.4 What is data type of second print?
Ans. int

3. Boolean
a = True Q3.1 What is output?
b = False Ans.
True False
print(a, b)

4. Multiple Assignment
a, b, c = 1, 2, 3 Q4.1 What is output?
print(a, b, c) Ans. 123
1
010243109 Introduction to Engineering by Amornphun Phunopas (APP)
Q4.2 Can variables be assigned in different type?
Ans. Yes

5. No value
a = None Q5.1 What is the value of a?
print(a) Ans. None

6. Input a value and show


print("Select operation.") Q6.1 What is the value of choice?
print("1.Fahrenheit to Celsius") Ans. be
can 1 or
2
print("2.Celsius to Fahrenheit")
choice = input("Enter choice(1/2):")
print("The choice is ", choice)

Lab 1 Problem

Aim: Write a program to swap two numbers using two variables.


Algorithm:
Step 1: Start
Step 2: Take two numbers from the user as input
Step 3: Swap two numbers
Step 4: Print the swapped numbers
Step 5: Stop
# write the code here
nume:int (inputCenter
the first number")
nume:int (inputCenter
the second number",
numbers "home,"and", aum 2)
print ("The
two are

numbers are ", nume,"and ",nume)


print (" The swapped

Output:
Enter the first number:15
Enter the second number:5
The two numbers are 15 and 5
The swapped numbers are 5 and 15

2
010243109 Introduction to Engineering by Amornphun Phunopas (APP)
Q4.2 Can variables be assigned in different type?
Ans.

5. No value
a = None Q5.1 What is the value of a?
print(a) Ans.

6. Input a value and show


print("Select operation.") Q6.1 What is the value of choice?
print("1.Fahrenheit to Celsius") Ans.
print("2.Celsius to Fahrenheit")
choice = input("Enter choice(1/2):")
print("The choice is ", choice)

Lab 1 Problem

Aim: Write a program to swap two numbers using two variables.


Algorithm:
Step 1: Start
Step 2: Take two numbers from the user as input
Step 3: Swap two numbers
Step 4: Print the swapped numbers
Step 5: Stop
# write the code here

Output:
Enter the first number:15
Enter the second number:5
The two numbers are 15 and 5
The swapped numbers are 5 and 15

2
010243109 Introduction to Engineering by Amornphun Phunopas (APP)

You might also like