Professional Documents
Culture Documents
Practical Set-1: The Result Is 600 The Result Is 70
Practical Set-1: The Result Is 600 The Result Is 70
Practical Set-1
# first condition
result = multiplication_or_sum(20, 30)
print("The result is", result)
# Second condition
result = multiplication_or_sum(40, 30)
print("The result is", result
Output
The result is 600
The result is 70
1
PDS 190170107147
for i in range(num):
sum = previousNum + i
print("Current Number", i, "Previous Number ", previousNum," Sum: ", sum)
previousNum = i
Output
Printing current and previous number sum in a given range(10)
inputStr = "pynative"
2
PDS 190170107147
Output
Orginal String is pynative
index[ 0 ] p
index[ 2 ] n
index[ 4 ] t
index[ 6 ] v
Output
Removing n number of chars
tive
3
PDS 190170107147
Output
Given list is [10, 20, 30, 40, 10]
result is True
4
PDS 190170107147
Output
Given list is [10, 20, 33, 46, 55]
Divisible of 5 in a list
10
20
55
Output
2
5
PDS 190170107147
def reverseCheck(number):
print("original number", number)
originalNum = number
reverseNum = 0
while (number > 0):
reminder = number % 10
reverseNum = (reverseNum * 10) + reminder
number = number // 10
if (originalNum == reverseNum):
return True
else:
return False
Output
original number 121
9.Given a two list of numbers create a new list such that new list
should contain only odd numbers from the first list and even
numbers from the second list
thirdList = []
6
PDS 190170107147
if (num % 2 != 0):
thirdList.append(num)
if (num % 2 == 0):
thirdList.append(num)
return thirdList
Output
First List [10, 20, 23, 11, 17]
Output
67
7
PDS 190170107147
7
Enter first number Enter second number Sum is 74
Output
My**Name**Is**James
Output
10,
8
PDS 190170107147
458.54
item = float(input())
floatNumbers.append(item)
Output
45.6
67.8
43.6
34.7
5.7
9
PDS 190170107147
15.write all file content into new file by skiping line 5 from
following file
count = 0
lines = fp.readlines()
count = len(lines)
if (count == 3):
count -= 1
continue
else:
fp.write(line)
count-=1
Given test.txt file:
line1
line2
line3
line4
line5
line6
line7
Output:
line1
10
PDS 190170107147
line2
line3
line4
line6
line7
Output
Enter three string nency ahir vaghamshi
quantity = 3
totalMoney = 1000
price = 450
statement1 = "I have {1} dollars so I can buy {0} football for {2:.2f} dollars."
11
PDS 190170107147
Output
I have 1000 dollars so I can buy 3 football for 450.00 dollars.
print(os.stat("test.txt").st_size == 0)
test.txt file:
line1
line2
line3
line4
line5
line6
line7
12