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)