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
def removeduplicates_v1(lst): | |
lst = set(lst) | |
return list(lst) | |
def removeduplicates_v2(lst): | |
new_lst = [] | |
for i in range((len(lst)-1)): | |
if (lst[i] not in new_lst): | |
new_lst.append(lst[i]) | |
return new_lst | |
eg = [1,2,3,4,1,2,3,4] |
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
def fibonnaci(x): | |
if(x == 1): | |
return 1 | |
elif(x == 0): | |
return 0 | |
else: | |
return fibonnaci(x -1) + fibonnaci(x -2) | |
number = int(input("Please entre the number of term of fibonnaci number")) | |
print("The number of ", number,"term of fibonnaci number is ", fibonnaci(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
def listEnds(list_x): | |
b = [0,0] | |
b[0]= list_x[0] | |
b[1] = list_x[len(list_x)-1] | |
return b | |
a = [5, 10, 15, 20, 25] | |
array = [] | |
array = listEnds(a) |
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
def checkprime(input): | |
counter = 0 | |
for i in range(1, input+1): | |
result = input // i | |
print(result, counter) | |
if (result * i == input): | |
counter += 1 | |
if (counter > 2): | |
return False | |
return True |
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
#include <stdio.h> | |
int main() | |
{ | |
int a, b, c, d; | |
printf("Enter fraction 1(numerator denominator) \n"); | |
scanf("%d %d", &a,&b); | |
printf("Enter fraction 2(numerator denominator) \n"); | |
scanf("%d %d", &c, &d); | |
if (b == 0 || d == 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
#include <stdio.h> | |
main() | |
{ | |
int i; | |
int p; | |
for(i = 1; i <=16; i++) | |
{ | |
for (p=1; p<=i; p++) | |
{ | |
printf("**"); |
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
#include <stdio.h> | |
main() | |
{ | |
printf("input x\n"); | |
int x; | |
scanf("%d", &x); | |
printf("input y\n"); | |
int y; | |
scanf("%d",&y); | |
int i; |
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 random | |
a=[] | |
b=[] | |
c=[] | |
for i in range (random.randint(10,20)): | |
a.append(random.randint(1,100)) |
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 random | |
number = random.randint(1,9) | |
print("type exit to leave") | |
attempt = 1 | |
while True: | |
guess = input("please guess a number from 1 to 9") | |
if guess != "exit": |
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
# i will do player vs comp | |
import random | |
will = 1 | |
while will == 1: | |
player = input("rock, paper, scissors") | |
comp = random.randint(1,3) | |
if comp ==1: | |
comp = "rock" |
NewerOlder