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
# Write a password generator in Python. | |
# strong passwords have a mix of lowercase letters, uppercase letters, numbers, and symbols. | |
# The passwords should be random, generating a new password every time the user asks for a new password. | |
# Include your run-time code in a main method. | |
import string | |
import random | |
characters = string.ascii_letters |
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
# Generate two random lists for different lengths | |
# and write a program that returns a list that contains only the elements | |
# that are common between the lists (without duplicates). | |
# Make sure your program works on two lists of different sizes. | |
import random | |
test1 = int(input("Enter the length of the first array: ")) | |
test2 = int(input("Enter the length of the second array: ")) |
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
# Print Fibonacci Series | |
a = 0 | |
b = 1 | |
test = int(input("Enter the range till you want the series: ")) | |
print(a) | |
print(b) | |
for i in range(test): |
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
# Generate a random number between 1 and 9 (including 1 and 9). | |
# Ask the user to guess the number, | |
# then tell them whether they guessed too low, too high, or exactly right. | |
import random | |
num = random.randint(1, 10) | |
flag = 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
# a list saved in a variable: a = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]. | |
# Write one line of Python that takes this list a | |
# and makes a new list that has only the even elements of this list in it. | |
a = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] | |
b = list(filter(lambda x: x % 2 == 0, a)) | |
print(b) |
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
# Ask the user for a string and print out whether this string is a palindrome or not. | |
raw = str(input("Enter a string: ")) | |
raw.replace(" ", "") | |
set1 = str.lower(raw[::-1]) | |
set2 = str.lower(raw[0::]) | |
if set2 == set1: | |
print("Palindrome") | |
else: | |
print("Not a palindrome") |
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
# Take two random lists | |
# and write a program that returns a list that contains only the elements | |
# that are common between the lists (without duplicates). | |
# Make sure your program works on two lists of different sizes. | |
import random | |
a = random.sample(range(100), 10) | |
b = random.sample(range(100), 15) | |
c = [] |
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
# Take two lists, say for example these two: | |
# a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] | |
# b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] | |
# and write a program that returns a list that contains only the elements | |
# that are common between the lists (without duplicates). | |
# Make sure your program works on two lists of different sizes. | |
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] | |
b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] | |
c = [] |
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
# Create a program that asks the user for a number | |
# and then prints out a list of all the divisors of that number. | |
num = int(input("Enter a number")) | |
check = list(range(1, num+5)) | |
for number in check: | |
if num % number == 0: | |
print(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
# Write a Python program to get a list, | |
# sorted in increasing order by the last element | |
# in each tuple from a given list of non-empty tuples. | |
# Sample List : [(2, 5), (1, 2), (4, 4), (2, 3), (2, 1)] |
NewerOlder