Skip to content

Instantly share code, notes, and snippets.

View Deep18-03's full-sized avatar
🏠
Working from home

Deep18-03

🏠
Working from home
View GitHub Profile
import datetime
name=input("Enter your name")
age=int(input('enter yout age'))
now=datetime.datetime.now()
current_year=now.year
year=(current_year-age)+100
print( name +' you will be at 100 in '+str(year)+' years' )
num=int(input('enter the first number'))
num1=int(input('enter the second number'))
def oddeven(num):
if num%2==0:
print('it is a even number')
elif num%4==0:
print('it is divisible by 4')
else:
print('it is a odd number')
'''Algorithm:
- Create new empty list
- For loop to iterate over each element
- If element < 5:
- Append the element into new list
- Print the new list'''
a = [1, 1, 2, 3, 5, 2, 13, 21, 3 4, 55, 89]
b=[]
for i in a:
if i < 5:
#use concept of list comprehension
a = [1, 1, 2, 3, 5, 2, 13, 21, 34, 55, 89]
print([a for a in a if a < 5])
@Deep18-03
Deep18-03 / singlelinepalindrome.py
Created March 29, 2020 18:20
palindrome program
'''
1.word[::-1] inverts the input
2.word.find(s) returns the index of s inside word or -1 if word doesnot contain s.since we use the entire input,
we get either 0 or-1
3.since bool(0)=False and bool(1)=True we simply add 1 to the result brfore we convert it ro the bool value '''
word=input("enter the basestring")
p=bool(word.find(word[::-1])+1)
print(p)
@Deep18-03
Deep18-03 / print all the divisors of that number.py
Created March 29, 2020 18:48
Create a program that asks the user for a number and then prints out a list of all the divisors of that number. (If you don’t know what a divisor is, it is a number that divides evenly into another number. For example, 13 is a divisor of 26 because 26 / 13 has no remainder.
'''
1.create a empty list
2.ask user for the number num
3.for loop to iterate up to that num
4.find all divior of that number using if
5.add all divsior in list
6.print the list
'''
lst=[]
num=int(input("enter the number"))
@Deep18-03
Deep18-03 / print all the divisors of that number.py
Created March 29, 2020 18:48
Create a program that asks the user for a number and then prints out a list of all the divisors of that number. (If you don’t know what a divisor is, it is a number that divides evenly into another number. For example, 13 is a divisor of 26 because 26 / 13 has no remainder.
'''
1.create a empty list
2.ask user for the number num
3.for loop to iterate up to that num
4.find all divior of that number using if
5.add all divsior in list
6.print the list
'''
lst=[]
num=int(input("enter the number"))
@Deep18-03
Deep18-03 / newlist has only even element from old list.py
Created March 29, 2020 19:11
created a python program to create a new list that has only even element from old list using list compresion #singleline code
'''
1.create a list using range()
2.use list comprehension concept
'''
a=list(range(1,11))
print=([a for a in a if a%2==0])
'''
Q:-Make a two-player Rock-Paper-Scissors game.
(Hint: Ask for player plays (using input), compare them, print out a message of congratulations to the winner,
and ask if the players want to start a new game)
steps:
1.take input from two player
2.compare the input of both players
3.Remember the rules:
Rock beats scissors
#guess the number program
from random import *
secret_no=randint(1,20)
for guess_taken in range(1,7):
guess_no=int(input("enter the number between 1 to 20 "))
if guess_no < secret_no:
print('your guess is low')
elif guess_no > secret_no: