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

Python One Shot

The document contains various Python code snippets demonstrating different functionalities such as checking for perfect numbers, palindromes, prime numbers, and Armstrong numbers. It also includes string manipulation methods and operations on NumPy arrays and lists, showcasing how to perform tasks like reshaping, concatenating, and sorting. Overall, it serves as a practical guide for basic programming concepts in Python.

Uploaded by

alicia.useless
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)
3 views4 pages

Python One Shot

The document contains various Python code snippets demonstrating different functionalities such as checking for perfect numbers, palindromes, prime numbers, and Armstrong numbers. It also includes string manipulation methods and operations on NumPy arrays and lists, showcasing how to perform tasks like reshaping, concatenating, and sorting. Overall, it serves as a practical guide for basic programming concepts in Python.

Uploaded by

alicia.useless
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

-------------------------------------------

n=int(input("enter any number"))


sum=0
for x in range(1,n):
if (n%x==0):
sum=sum+x
if(sum==n):
print("perfect number")
else:
print("not a perfect number")
---------------------------------------------
n=input("enter any number")
if (n==n[::-1]):
print("palindrome number")
else:
print("not a palindrome number")
---------------------------------------------
n=int(input("enter a number"))
for i in range (2, num):
if n%i==0:
print ("not prime")
break
else:
print("prime")
---------------------------------------------
n=int(input("enter a number"))
m= str(n)
o= len(m)
p=0
for x in range (o):
a += int(p)**o
if (d==a):
print("number is armstrong")
else:
print("number is not armstrong")
---------------------------------------------
STRING
s = "biotechnology"

print("Length:", len(s)) # 1. len()

print("Uppercase:", [Link]()) # 2. upper()

print("Lowercase:", [Link]()) # 3. lower()

print("Ends with 'World':", [Link]("World")) # 4. endswith(value)

print("Starts with 'Hello':", [Link]("Hello")) # 5. startswith(value)

print("Position of '123':", [Link]("123")) # 6. find(value)

print("Is lowercase:", [Link]()) # 7. islower()

print("Replace 'World' with 'Python':", [Link]("World", "Python")) # 8. replace(oldvalue,


newvalue)

print("Count of 'l':", [Link]("l")) # 9. count(value)

print("Is alphabet only:", [Link]()) # 10. isalpha()

num = "12345"

print("Is digit:", [Link]()) # 11. isdigit()

print("Is alphanumeric:", [Link]()) # 12. isalnum()

words = ["Python", "is", "fun"]

print("Joined string:", " ".join(words)) # 13. join(iterable)

print("Sliced string:", s[0:10:2]) # 14. Slicing [start:end:step]


LISTS
import numpy as np

а = [Link] ([10,20,30,40,50,60])

print (a[0]) # output: 10

print (a[2]) # output: 30

print (a[1:4]) # output: [20,30,40]

print(a[::2]) #output: [10,50,50]

print (a. shape) # shape tells dimensions output: 6

print (a reshape (2,3)) # reshape changes the dimension

# output: [10, 20, 30


40, 50, 60] (2rows 3 columns)

iterating
for element in a :
print (element) # output: 10,20,30,40, 50
print([Link] (a, b))
print (np.array_split (a,3)) # output: [ array ([10, 20]),
array ([30, 40]),
array ([50, 60]) ]
print ([Link] (a==30))
print (np. sort (a)) #puts in an order
------------------------------------------------------------------------------------------------
list = [10,20,30]

print (list, append (40)) # adds item at end

print(list. insert(1, 15)) # adds item at indexed no.

print (list. extend ([50,60])) # adds multiple item

print([Link]()) # sorts in an order

if 30 in list:

print("30 found at index: ", [Link] (30))

else:

print("30 not found")

You might also like