0% found this document useful (0 votes)
5 views4 pages

Simple

Uploaded by

Satyam Amrutkar
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)
5 views4 pages

Simple

Uploaded by

Satyam Amrutkar
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/ 4

In [8]: #1

print('hello')
tup_list = [(1,6), (2,5), (3,4)]
maxels = [max(t) for t in tup_list]
maxt = max(maxels)
print(maxt)

hello
6

In [9]: #2
lst = list(map(float, input("Enter 3 float nums seperated by a comma").split
print(sum(lst))

33.0

In [10]: #3
import math
r = float(input("Enter radius: "))
vol = 4/3 * math.pi * r**3
print(vol)

1436.7550402417319

In [12]: #4
def fact(n):
if n==0 or n==1:
return 1
return n*fact(n-1)

n = int(input("Enter a number: "))


print(fact(n))

24

In [13]: #5
cover_price = 24.95
copies = 60
discount_price = cover_price * 0.6
total_cost = discount_price*copies + 3 + 0.75*(copies-1)
print(total_cost)

945.4499999999999

In [14]: #6
import math
r = float(input("Enter radius: "))
area = math.pi * r**2
print(area)

153.93804002589985

In [16]: #7
lst = list(map(int, input("Enter 3 numbers seperated by space: ").split(" "
print(f"Max: {max(lst)}, Min: {min(lst)}")

Max: 4, Min: 2

In [27]: #8
biggest = lambda x,y : x if x>y else y
a,b = map(int, input("Enter two nums seperated by space:").split(" "))
print(f"Bigger Value: {biggest(a,b)}")

lst = input("Enter items into a list seperated by spaces: ").split()


item = input("Enter item to count occurence: ")
ct = lst.count(item)
print(f"{item} appears in the list {ct} times")

Bigger Value: 30
10 appears in the list 2 times

In [29]: #9
n = int(input("Enter a number: "))
for i in range (1,11):
print(f"{n} x {i} = {n*i}")

powers = {2 ** x for x in range(11)}


print(powers)

5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
{32, 1, 2, 64, 4, 128, 256, 512, 8, 1024, 16}

In [32]: #10
num = input("Enter a number:")
n = len(num)
total = 0
for digit in num:
total+= int(digit)**n
if int(num) == total:
print("Armstrong")
else:
print("Not Armstrong")

Not Armstrong

In [34]: #11
cel = float(input("Enter celsius value: "))
far = (9/5)*cel + 32
print(f"{cel} C = {far} F")

37.5 C = 99.5 F

In [36]: #12
r = int(input("Enter number of rows: "))
for i in range(r):
for j in range(r-i-1):
print(" ", end='')
for k in range(i+1):
print("*", end=' ')
print()
*
* *
* * *
* * * *
* * * * *

In [37]: #13
a,b = map(int, input("Enter two nums seperated by space:").split(" "))
c = a if a>b else b
print(f"Max Value: {c}")

Max Value: 3

In [38]: #14
name = input("Enter name: ")
age = int(input("Enter age: "))
position = input("Enter position: ")
print(f"Employee Data: Name: {name}, Age: {age}, Position: {position}")

Employee Data: Name: aaa, Age: 21, Position: ceo

In [43]: #15 - Command Line args - run in sep file - python .\cmd.py abc def ghi
import sys
n = len(sys.argv)
print("Arguments Passed: ")
for i in range(1,n):
print(sys.argv[i])

Arguments Passed:
-f
/home/karthik/.local/share/jupyter/runtime/kernel-5d01147f-72a4-4e7b-b38d-
a8d53cea0f95.json

In [48]: #16
nums = ['zero','one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight'
n = int(input("Enter a single digit number: "))
print(nums[n])

seven

In [51]: #17
square = lambda x : x**2
n = int(input("Enter a number: "))
print(f"Square: {square(n)}")

Square: 64

In [52]: #18
lst = list(map(int, input("Enter 3 numbers seperated by space: ").split(" "
print(f"Max: {max(lst)}, Min: {min(lst)}")

Max: 33, Min: 23

In [53]: #19
n = int(input("Enter a number: "))
sq = n**0.5
print(f"Square Root: {sq}")

Square Root: 1.4142135623730951

In [ ]:

In [55]: # 20
lst = list(map(int, input("Enter elements of list seperated by space").split
even_nums = list(filter(lambda x : x%2 == 0, lst))
print(even_nums)

[2, 4]

In [56]: #21
main = input("Enter main string: ")
sub = input("Enter sub string: ")
pos = list(i for i in range (len(main)) if main.startswith(sub, i))
print(pos)

[1, 5, 9, 12, 14]

In [58]: #22
main = input("Enter a string: ").lower()
letter_freq = {}
for char in main:
if char.isalpha():
if char in letter_freq:
letter_freq[char] += 1
else:
letter_freq[char] = 1
print(letter_freq)

{'a': 3, 'b': 2, 'c': 2}

In [ ]:

In [ ]:

You might also like