Saturday, 23 October 2021

39: Square of As

#This program will write as many As as the square of the number you give, taking into account that it will only write n As per line and n lines
#Get the number of As
try:
 A_squared = int(input('Please give me the number at which you want to square A \n>'))
except ValueError:
 print('That is not a valid number of As')
 
#Print them
for i in range(0, A_squared):
 for j in range(0,A_squared):
   print('A', end = '')
 print('')

Saturday, 21 November 2020

40. Pyhton Song

#This is to show you how to create several outputs with just one piece of code 

def lyrics0(stuff, num_repeats): #This command tells python that lyrics0 is two things:stuff and num_repeats


  return stuff*num_repeats #This means that when lyrics0 is called, it will print stuff multiplied by num_repeats


lyrics1 = lyrics0('Row ',3) + lyrics0('Your Boat. ', 1)+lyrics0('''

''', 1) #This is saying first to write three 'Row', one 'Your Boat' and one paragraph for spacing, because the script is a poem


lyrics2 = lyrics0('Gently down the stream  ', 1)+lyrics0('''

''', 1) #lyrics2, lyrics3 and lyrics4 do the same as lyrics1 but with different things to write


lyrics3 = lyrics0('Happily  ',4)+lyrics0('''

''', 1)


lyrics4 = lyrics0('Life is such a dream ', 1)


song = (lyrics1 + lyrics2 + lyrics3 + lyrics4+'''

        ''' + '''

''') #this command is saying to python: 'song is lyrics1, lyrics2, lyrics3, lyrics4 and two paragraphs all joined together


print(song*4) #As the last part, we are telling python to print song four times.

#Miguel Angel Trejo's song

Monday, 8 June 2020

51 . Bruteforce attack

#On Monday you created a password : this is the code:

print ('Hello, Its Monday')
print ('create a number-password')
NEWPASS = int(input())
print ('Thank you, bye')
print('')

#On Tuesday hackers entered the system.
#THE AUTOMATIC BRUTEFORCE STARTS HERE.
#Hackers cannot see the above code (The monday password)

import time
print ('Hello, Its Tuesday')

a=0
while NEWPASS != a:
  print ('To enter the system please introduce your password')
  a=a+1
  print (a)
   
print ('Welcome to MI6')

50 One-word encryption (permutation code) hacked (+ grammar attack)

#One-word encryption (permutation code) hacked (+ grammar attack)
#Think of the name of a common animal.
#Encrypt it: change its letters of order cat---> act


# HACKED
while True:
    print ('')
    print ('Paste the encrypted text here:')
    ET = str(input())

    import itertools

    l = itertools.permutations(str(ET))
    output= ([str(''.join(x)) for x in l])
    print (output)

    #for elem in ET:
     #   print ((elem, end = '') )                #  , end = ''
     
    #elem = elem.lower()

###########################################################
#DICC is the dictionary of
    while True: 
        DICC = ["cat", "bat", "rat", "elephant", "dog"]

        for x in DICC:
            if x in output:
                print (x)
            else:
                print ('...')
        break

     
 


 

 


49 #Caesar code Encrypt / Decrypt with password

#Caesar code Encrypt / Decrypt with password

#List of characters:
#import string
#print (string.printable)

L1 = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&()*+,-./:;<=>?@[\]^_`{|}~' *999999 #This multiplies the extension of L1
           #L1 must contain all possible keyboard symbols
           #Randomeness in L1 increases layer of unpredictivity

while True:
    print ('')
    print ('')
    print ('Encript=E /Decrypt=D')
    EorD = input()
    EorD = EorD.lower()
    if EorD == 'e':
       
        #Message
        print('')
        print ('Introduce text to encrypt.')
        MESS = input()
       
        #Password (number of translations)
        print ('6-digit Numerical Password')
        PASS = int(input())
       
        #Item by item translation
        for LETTER in MESS:
            NEWPOS = L1.find(LETTER)+ PASS
            if NEWPOS == 0 :
                print ('fuc')
                break
            elif NEWPOS >= len(L1):
                print ('try again with a smaller password')
            print (L1[NEWPOS], end = '')
           
    elif EorD == 'd':
        #Message
        print('')
        print ('Paste text to decrypt.')
        MESS = input()
       
        #Password (number of translations)
        print ('6-digit Numerical Password')
        PASS = int(input())
       
        #Item by item translation
        for LETTER in MESS:
            NEWPOS = L1.find(LETTER)- PASS
            if NEWPOS < 0:
                print ( end = '')
           
            print (L1[NEWPOS], end = '')

     
       
 

48 Decryption: Caesar

#Caesar code DECRYPT -1

#L1 = ['a','e'] # + swap 'find' for 'index'
L1 = 'aeiou'
print (' introdu')
MESS = input ()

for LETTER in MESS:
    NEWPOS = L1.find(LETTER)-1 # Decrypt +1 ---> -1
    if NEWPOS == -2 :
        print ('\nthe letter ' + LETTER+ ' is not included')
        break
    elif NEWPOS <0:  # >= len (L1) -----> < 0
        NEWPOS = len(L1) -1 # 0 ----> len(L1) -1       
    print (L1[NEWPOS], end = '')

47 Encryption: Caesar

#Caesar code

#L1 = ['a','e'] # + swap 'find' for 'index'
L1 = 'aeiou'
print (' introdu')
MESS = input ()

for LETTER in MESS:
    NEWPOS = L1.find(LETTER)+1 #find the position in L1, +1
    if NEWPOS == 0 :
        print ('\nthe letter ' + LETTER+ ' is not included so i stop')
        break #quit() if you want to kill it
    elif NEWPOS >= len(L1):
        NEWPOS = 0    #solving last item +1 error
    #print (L1.find(LETTER))  #Finds the position of the item in a list
    print (L1[NEWPOS], end = '') #cancels the default print-newline

Tuesday, 2 June 2020

39. Upeercase / Lowercase

print ('Do you believe in God?')
a = input ( ) 
a = a.lower() #All goes lowercase. Try capitals and see

if a == ('yes'):
    print ('You are a believer')
elif a == ('no'):
    print ('You are either an agnostic or an atheist')
else:
    print ('No wanna talk with me? Bye!')

38. itertools.permutations(str(myInt))

import itertools
myInt = 123
l = itertools.permutations(str(myInt))
for x in l:
  print (x)

Monday, 20 April 2020

47 #Painting in python

#Making a MANDALA in python

print('choose a colour that will be the colour of the line drawn')
colourline=input()
print('choose a colour that will be the filling colour')
colourfill=input()
print('choose a number from 100 to 250 that will be the number of pixels the arro moves forwards creating a line')
a=int(input())
print('now choose a number from 90 to 360 that will be the degrees the arrow turns clockwise')
b=int(input())
print('write a number from 10 to 70 that will be the diameter of the circle that the arrow draws')
c=int(input())

from turtle import *
color(colourline,colourfill) #1st colour is the colour of the line and 2nd is the colour it feels the picture in when it's finished
begin_fill()
while True:
    forward(a) #number of pixels it moves forward
    right(b)#degrees it turns anti-clockwise(left) and clockwise(right)
    circle(c)#draws a circle of a diameter of the number you've said to him after moving the number of pixels you've told python

    if abs(pos()) < 1: #this will make it so that the arrow dosen't stop the fist time it reaches the place said
        print('Run again? (yes/no): ')
        answer=input()
        if answer == 'yes':
            continue #this will repeat the pattern created
        if answer == 'no':
            break #this will stop the program
end_fill() #this command will fill the final picture with the second colour chosen by the person who tries the program
done()

Saturday, 30 November 2019

46 #myClock ext stop or infinity.py

#myClock ext stop or infinity.py
from datetime import datetime

while True:
    print ()
    print ('whatz the distance of silence?')
    print ('option stop or infinity?')
    soi = input()
    if soi == 'infinity':
        while True:
            now = datetime.now()
            month = str(now.month)
            day = str(now.day)
            year = str(now.year)
            hour = str(now.hour)
            minutes = str(now.minute)
            seconds = str(now.second)

            rightnow = str (year + month + day+ hour + minutes + seconds)
            print (now)

    elif soi =='stop':
        print ('how many times?')
        times = int(input())

        for guessesTaken in range(1, times):
            now = datetime.now()
            month = str(now.month)
            day = str(now.day)
            year = str(now.year)
            hour = str(now.hour)
            minutes = str(now.minute)
            seconds = str(now.second)

            rightnow = str (year + month + day+ hour + minutes + seconds)
            print (now)

    else:
        print('try again')
         

Friday, 29 November 2019

# 45 SAVING DATA in a csv DOC

#45 My Zoo. #SAVING DATA in a csv DOC

animals = []
while True:
    print ('Name of animals you have. Type FFF to finish')
    newname=input()
    animals.append(newname)
    animals.sort()
    print (animals)
 
    if newname == 'FFF':
        animals.remove(newname)
        print ()
        print ('This is your list: ')
        animals.sort()
        print (animals)
        break

print()
print ('Need to add more?')
YESNO = input()
if YESNO =='yes':
    while True:
        print ('Name of animals you want to add. Type XXX to finish')
        newname=input()
        animals.append(newname)
        animals.sort()
        print (animals)
     
 
        if newname == 'XXX':
            animals.remove(newname)
            print ()
            print ('This is your list: ')
            animals.sort()
            print (animals)
            break

elif YESNO == 'no':
    print (animals)
    print ('Thank you.')

print ()
print ('Need to delete any?')
YESNO2 = input()
if YESNO2 =='yes':
    while True:
        print ('Name of animals you want to remove. Type XXX to finish')
        removeName=input()
        if removeName != 'XXX':
            animals.remove(removeName)
            animals.sort()
            print (animals)
 
        elif removeName == 'XXX':
            print ('This is your list: ')
            animals.sort()
            print (animals)
            break
     

elif YESNO2 == 'no':
    animals.sort()
    print (animals)
    print ('Thank you. Let´s save now the data')
    print()

################################################################
#SAVING DATA in a csv DOC
import csv

print ('Name the csv document remember to finish with: .csv')
csvDOC = input()

with open(csvDOC, 'w') as csv_file:
    csv_writer = csv.writer(csv_file, delimiter=',')
    csv_writer.writerow(animals)

 

44 #My Zoo. Adding Values to a list. Extended

#44 My Zoo. Adding Values to a list. Deleting

animals = []
while True:
    print ('Name of animals you have. Type FFF to finish')
    newname=input()
    animals.append(newname)
    print (animals)
   
    if newname == 'FFF':
        animals.remove(newname)
        print ()
        print ('This is your list: ')
        print (animals)
        break

print()
print ('Need to add more?')
YESNO = input()
if YESNO =='yes':
    while True:
        print ('Name of animals you want to add. Type XXX to finish')
        newname=input()
        animals.append(newname)
        print (animals)
       
   
        if newname == 'XXX':
            animals.remove(newname)
            print ()
            print ('This is your list: ')
            print (animals)
            break

elif YESNO == 'no':
    print (animals)
    print ('Thank you.')

print ()
print ('Need to delete any?')
YESNO2 = input()
if YESNO2 =='yes':
    while True:
        print ('Name of animals you want to remove. Type XXX to finish')
        removeName=input()
        if removeName != 'XXX':
            animals.remove(removeName)
            print (animals)
   
        elif removeName == 'XXX':
            print ('This is your list: ')
            print (animals)
            break
     

elif YESNO2 == 'no':
    print (animals)
    print ('Thank you.')

Friday, 22 November 2019

43 #My Zoo. Adding Values to a list

#My Zoo. Adding Values to a list

animals = []
while True:
    print ('Name of animals you have. Type FFF to finish')
    newname=input()
    animals.append(newname)
 
    if newname == 'FFF':
        animals.remove(newname)
        print ('This is your list: ')
        print (animals)
        break

42 #iNTRODUCING DATA FROM PROMPT. EXTENDED

#iNTRODUCING DATA FROM PROMPT. EXTENDED


friendNames = []
while True:
    print('Enter name of a friend ' + str(len(friendNames) + 1) +
' (Or enter F when finished.):')
    name = input()
    if name == 'F':
        break
    friendNames = friendNames + [name] # list concatenation

while True:
    print ('Name a friend to check he is in the list')
    print ('Type FFF to finish')
    CHECK = input()
    if (CHECK) in friendNames:
        print ('Yes')
        print()
    elif (CHECK) == ('FFF'):
        break
    else:
        print ('Nope, this name is not in the list')
        print ()

print ('Do you want to see the complete list?')
YESNO = input()
if YESNO == ('yes'):
    print('The friends names are:')
    for name in friendNames:
        print(name)
else:
    print ('Let´s continue')

41. #iNTRODUCING DATA FROM PROMPT

#iNTRODUCING DATA FROM PROMPT


friendNames = []
while True:
    print('Enter name of a friend ' + str(len(friendNames) + 1) +
' (Or enter F when finished.):')
    name = input()
    if name == 'F':
        break
    friendNames = friendNames + [name] # list concatenation

print('The friends names are:')
for name in friendNames:
    print(' ' + name)

Thursday, 21 November 2019

40 #INDEXING, #LISTS

#INDEXING
#Requesting data from lists!!!

#Lists01 Calling one specific value
print ('#Lists01')
L01 = ["cat", "bat", "rat", "elephant"]
print (L01 [1])

print()

#Lists02 Calling specific values in 2 lists
print ('#Lists02')
L02 = [['cat', 'bat'], [10, 20, 30, 40, 50]]
print (L02[0])
print (L02[0][1])
print (L02[1][4])

print ()

#Lists03 Calling out a specific value counting from the back
print ('#Lists03')
L03 = ['cat', 'bat', 'rat', 'elephant']
print (L03[-1])
print (L03[-3])
print ('The ' + L03[-1] + ' is afraid of the ' + L03[-3] + '.')

print()

#Lists04 Calling out a series of values
print ('#Lists04')
L04 = ['cat', 'bat', 'rat', 'elephant']
print (L04[0:4])
print (L04[1:3])
print (L04[0:-1])
print (L04[:2])
print (L04[1:])
print (L04[:])
print (len(L04))

print ()

#Lists05 Changing the values within the list
print ('#Lists05')
L05 = ['cat', 'bat', 'rat', 'elephant']
print (L05)
L05[1]= 'ant'
print (L05)
L05[-1]= 'dog'
print (L05)

print ()

#List06 Replication and concatenation
print ('#Lists06')
L06 = [1, 2, 3] + ['A', 'B', 'C']
print (L06)
print ((L06)*3)

print ()


#List07 Removing values with del
print ('#Lists07')
L07 = ['cat', 'bat', 'rat', 'elephant']
print (L07)
del L07[2]
print (L07)
del L07[2]
print (L07)















Friday, 29 April 2016

37. Questionnaire Extended (Name, Class Date, Activity Code)

#Participant data:

print ('Whats your name?')
NAME = input()
print ()
print (NAME + ', which is your class?')
CLASS = input ()
print ()

#Questionaire CODE
print ('ASK YOUR TEACHER FOR THE QUESTIONNAIRE CODE')
CODE = input()
print()

#Scores are set to 0
a=0
b=0
TOTAL = a+b

#Q1
print("Q1: Which is ...  ")

Q1 = ''
Q1 = input()

if Q1 ==("yes"):
    print ('correct')
    TOTAL = TOTAL + 1
elif Q1 ==("butt"):
    print ("10 extra points")
    TOTAL = TOTAL + 10
else:
    print ('incorrect')
    TOTAL = TOTAL - 1
print ('your points are ?...')
print (TOTAL)

#Q2
print("Q2: Why did ... ")

Q2 = ''
Q2 = input()

if Q2 ==("yes"):
    print ('correct')
    TOTAL = TOTAL + 1

elif Q2 ==("butt"):
    print ("10 extra points")
    TOTAL = TOTAL + 10
else:
    print ('incorrect')
    TOTAL = TOTAL - 1
print ('your points are ?...')
print (TOTAL)

#Q3 Copy and paste #1 and modify

#SCORES and DATE

import time
localtime = time.asctime( time.localtime(time.time()) )

print()
print ('****************** SHOW THIS TO TEACHER TO CHECK ***************')
print ('Name: ' + NAME)
print ('Class: '+ CLASS)
print ('Total Points: ... '), print(TOTAL)
print ('Activity CODE: ' + CODE)
print ('Today is: ' + localtime)

36. Questionnaire


#Q1
print("Q1: x  ")

Q1 = ''
Q1 = input()

if Q1 ==("yes"):
    print ('correct')
    TOTAL = TOTAL + 1
elif Q1 ==("butt"):
    print ("10 extra points")
    TOTAL = TOTAL + 10
else:
    print ('incorrect')
    TOTAL = TOTAL - 1
print ('your points are ?...')
print (TOTAL)

#Q2
print("Q2:  ")

Q2 = ''
Q2 = input()

if Q2 ==("yes"):
    print ('correct')
    TOTAL = TOTAL + 1

elif Q2 ==("butt"):
    print ("10 extra points")
    TOTAL = TOTAL + 10
else:
    print ('incorrect')
    TOTAL = TOTAL - 1
print ('your points are ?...')
print (TOTAL)


35. pre-Cognition (Expanded)

#Pre-cognition

# Import the modules
import random

a=0
b=0

while True:
    print ('')
    print ('Think of a number from 1 to 9  ##########################')
    ANS = int(input())
    answers = random.randint(1,9)

    if ANS == answers:
        a=a+1
       
    elif ANS != answers:
        b=b+1

    print (' aleatorial bot says: ')
    print(answers)    
    print ('')
    print ('ATTEMPTS /20 : ')
    TOTAL = a+b
    print (TOTAL)
    print ('')
    print ('YES:')
    print (a)
    print ('NO:')
    print (b)
    print ('')
   
TOTAL = a+b
    YOURSCORE = (a/TOTAL)*100
    print('YOUR SCORE as % is :')
    print (YOURSCORE)

    if YOURSCORE <=11.11:
        print ('Pre-Cognition level = 0/9')
    elif 11.11 < YOURSCORE <=22.22:
        print ('Pre-Cognition level = 1/9')
    elif 22.22 < YOURSCORE <=33.33:
        print ('Pre-Cognition level = 2/9')
    elif 33.33 < YOURSCORE <=44.44:
        print ('Pre-Cognition level = 3/9')
    elif 44.44 < YOURSCORE <=55.55:
        print ('Pre-Cognition level = 4/9')
    elif 55.55 < YOURSCORE <=66.66:
        print ('Pre-Cognition level = 5/9')
    elif 66.66 < YOURSCORE <=77.77:
        print ('Pre-Cognition level = 6/9')
    elif 77.77 < YOURSCORE <=88.88:
        print ('Pre-Cognition level = 7/9')
    elif 88.88 < YOURSCORE <=99.99:
        print ('Pre-Cognition level = 8/9')      
    elif YOURSCORE ==100:
        print ('Pre-Cognition level = 9/9. Perfection')

    if TOTAL == 20:
        print ('thank you')
        break