This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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: |
OlderNewer