정적 크롤링 하기~!

import requests
from bs4 import BeautifulSoup


def finding(biglist):
    country = input("#: ")
    if country.isdecimal():
        number = int(country)
        if number <= len(biglist):
            print("You chose", biglist[number][1])
            print("The currency code is", biglist[number][3].upper())
        else:
            print("Choose a number from the list.")
            return finding()
    else:
        print("That wasn\'t a number.")
        return finding()


def findurlcode():
    indeed_result = requests.get('https://www.iban.com/currency-codes')
    indeed_soup = BeautifulSoup(indeed_result.text, "html.parser")
    datalist = indeed_soup.find(
        "table", {"class": "table table-bordered downloads tablesorter"})
    pages = datalist.find_all('tr')
    biglist = []
    count = 0
    for i in pages[1:]:
        minilist = []
        minilist.append(count)
        for k in i:
            if k != "\n":
                data = str(k.string)
                if data.isdecimal():
                    minilist.append(int(data))
                else:
                    minilist.append(data[0] + data[1:].lower())
        if type(minilist[4]) == type(0):
            biglist.append(minilist)
            count += 1
    return biglist


def firstwork():
    biglist = findurlcode()
    for i in biglist:
        print("#", i[0], i[1])
    return biglist


def startgame():
    print("Hello! Please choose select a country by number:")
    biglist = firstwork()
    finding(biglist)

 

 

내일꺼랑 연관있어 함수 정리 잘해놓기~

 

블로그 이미지

Or71nH

,

퀴즈 

1. 스플릿 하기

2.url 만들기

3.url 검사

단!!! com 만되게 해놧다 
co.kr은 안됨!~!!
나중에 정규식 고쳐야한다~!

 

import requests
from bs4 import BeautifulSoup


def finding(biglist):
    country = input("#: ")
    if country.isdecimal():
        number = int(country)
        if number <= len(biglist):
            print("You chose", biglist[number][1])
            print("The currency code is", biglist[number][3].upper())
        else:
            print("Choose a number from the list.")
            return finding()
    else:
        print("That wasn\'t a number.")
        return finding()


def findurlcode():
    indeed_result = requests.get('https://www.iban.com/currency-codes')
    indeed_soup = BeautifulSoup(indeed_result.text, "html.parser")
    datalist = indeed_soup.find(
        "table", {"class": "table table-bordered downloads tablesorter"})
    pages = datalist.find_all('tr')
    biglist = []
    count = 0
    for i in pages[1:]:
        minilist = []
        minilist.append(count)
        for k in i:
            if k != "\n":
                data = str(k.string)
                if data.isdecimal():
                    minilist.append(int(data))
                else:
                    minilist.append(data[0] + data[1:].lower())
        if type(minilist[4]) == type(0):
            biglist.append(minilist)
            count += 1
    return biglist


def firstwork():
    biglist = findurlcode()
    for i in biglist:
        print("#", i[0], i[1])
    return biglist


def startgame():
    print("Hello! Please choose select a country by number:")
    biglist = firstwork()
    finding(biglist)
블로그 이미지

Or71nH

,

퀴즈

"""
Again, the code is broken, you need to create 4 functions.
  - add_to_dict: Add a word to a dict.
  - get_from_dict: Get a word from inside a dict.
  - update_word: Update a word inside of the dict.
  - delete_from_dict: Delete a word from the dict.

All this functions should check for errors, follow the comments to see all cases you need to cover.

There should be NO ERRORS from Python in the console.
"""

def add_to_dict():
  pass

def get_from_dict():
  pass

def update_word():
  pass

def delete_from_dict():
  pass

# \/\/\/\/\/\/\ DO NOT TOUCH  \/\/\/\/\/\/\

import os

os.system('clear')


my_english_dict = {}

print("\n###### add_to_dict ######\n")

# Should not work. First argument should be a dict.
print('add_to_dict("hello", "kimchi"):')
add_to_dict("hello", "kimchi")

# Should not work. Definition is required.
print('\nadd_to_dict(my_english_dict, "kimchi"):')
add_to_dict(my_english_dict, "kimchi")

# Should work.
print('\nadd_to_dict(my_english_dict, "kimchi", "The source of life."):')
add_to_dict(my_english_dict, "kimchi", "The source of life.")

# Should not work. kimchi is already on the dict
print('\nadd_to_dict(my_english_dict, "kimchi", "My fav. food"):')
add_to_dict(my_english_dict, "kimchi", "My fav. food")


print("\n\n###### get_from_dict ######\n")

# Should not work. First argument should be a dict.
print('\nget_from_dict("hello", "kimchi"):')
get_from_dict("hello", "kimchi")

# Should not work. Word to search from is required.
print('\nget_from_dict(my_english_dict):')
get_from_dict(my_english_dict)

# Should not work. Word is not found.
print('\nget_from_dict(my_english_dict, "galbi"):')
get_from_dict(my_english_dict, "galbi")

# Should work and print the definiton of 'kimchi'
print('\nget_from_dict(my_english_dict, "kimchi"):')
get_from_dict(my_english_dict, "kimchi")

print("\n\n###### update_word ######\n")

# Should not work. First argument should be a dict.
print('\nupdate_word("hello", "kimchi"):')
update_word("hello", "kimchi")

# Should not work. Word and definiton are required.
print('\nupdate_word(my_english_dict, "kimchi"):')
update_word(my_english_dict, "kimchi")

# Should not work. Word not found.
print('\nupdate_word(my_english_dict, "galbi", "Love it."):')
update_word(my_english_dict, "galbi", "Love it.")

# Should work.
print('\nupdate_word(my_english_dict, "kimchi", "Food from the gods."):')
update_word(my_english_dict, "kimchi", "Food from the gods.")

# Check the new value.
print('\nget_from_dict(my_english_dict, "kimchi"):')
get_from_dict(my_english_dict, "kimchi")


print("\n\n###### delete_from_dict ######\n")

# Should not work. First argument should be a dict.
print('\ndelete_from_dict("hello", "kimchi"):')
delete_from_dict("hello", "kimchi")

# Should not work. Word to delete is required.
print('\ndelete_from_dict(my_english_dict):')
delete_from_dict(my_english_dict)

# Should not work. Word not found.
print('\ndelete_from_dict(my_english_dict, "galbi"):')
delete_from_dict(my_english_dict, "galbi")

# Should work.
print('\ndelete_from_dict(my_english_dict, "kimchi"):')
delete_from_dict(my_english_dict, "kimchi")

# Check that it does not exist
print('\nget_from_dict(my_english_dict, "kimchi"):')
get_from_dict(my_english_dict, "kimchi")

# \/\/\/\/\/\/\ END DO NOT TOUCH  \/\/\/\/\/\/\
"""
Again, the code is broken, you need to create 4 functions.
  - add_to_dict: Add a word to a dict.
  - get_from_dict: Get a word from inside a dict.
  - update_word: Update a word inside of the dict.
  - delete_from_dict: Delete a word from the dict.

All this functions should check for errors, follow the comments to see all cases you need to cover.

There should be NO ERRORS from Python in the console.
"""

def add_to_dict(lalal, *arg):
  if str(type(lalal)) == "<class 'dict'>":
    if len(arg) == 2:
      if arg[0] in lalal:
        print(f"{arg[0]} is already on tje dictionary. Won't add.")
      else:
        lalal[arg[0]] = arg[1]
        print(f"{arg[0]} has been added.")
    else:
      print("You need to send a word and a definiton.")
  else:
    print(f"You need to send a dictionary. You sent: {type(lalal)}")
  pass

def get_from_dict(lalal, *arg):
  if str(type(lalal)) == "<class 'dict'>":
    if len(arg) == 1:
      if arg[0] in lalal:
        print(f"{arg[0]}: {lalal[arg[0]]}")
      else:
        print(f"{arg[0]} was not found in this dict.")
    else:
      print("You need to send a word to search for.")
  else:
    print(f"You need to send a dictionary. You sent: {type(lalal)}")
  pass


def update_word(lalal, *arg):
  if str(type(lalal)) == "<class 'dict'>":
    if len(arg) == 2:
      if arg[0] in lalal:
        lalal[arg[0]] = arg[1]
        print(f"{arg[0]} has been updated to: {arg[1]}")
      else:
        print(f"{arg[0]} is not on the dict. Can't update non-existing word.")
    else:
      print("You need to send a word and a definiton to update.")
  else:
    print(f"You need to send a dictionary. You sent: {type(lalal)}")
  pass

  pass

def delete_from_dict(lalal, *arg):
  if str(type(lalal)) == "<class 'dict'>":
    if len(arg) == 1:
      if arg[0] in lalal:
        del lalal[arg[0]]
        print(f"{arg[0]} has been deleted.")
      else:
        print(f"{arg[0]} is not on in this dict. Won't delete.")
    else:
      print("You need to specify a word to delete.")
  else:
    print(f"You need to send a dictionary. You sent: {type(lalal)}")
  pass

# \/\/\/\/\/\/\ DO NOT TOUCH  \/\/\/\/\/\/\

import os

os.system('clear')


my_english_dict = {}

print("\n###### add_to_dict ######\n")

# Should not work. First argument should be a dict.
print('add_to_dict("hello", "kimchi"):')
add_to_dict("hello", "kimchi")

# Should not work. Definition is required.
print('\nadd_to_dict(my_english_dict, "kimchi"):')
add_to_dict(my_english_dict, "kimchi")

# Should work.
print('\nadd_to_dict(my_english_dict, "kimchi", "The source of life."):')
add_to_dict(my_english_dict, "kimchi", "The source of life.")

# Should not work. kimchi is already on the dict
print('\nadd_to_dict(my_english_dict, "kimchi", "My fav. food"):')
add_to_dict(my_english_dict, "kimchi", "My fav. food")


print("\n\n###### get_from_dict ######\n")

# Should not work. First argument should be a dict.
print('\nget_from_dict("hello", "kimchi"):')
get_from_dict("hello", "kimchi")

# Should not work. Word to search from is required.
print('\nget_from_dict(my_english_dict):')
get_from_dict(my_english_dict)

# Should not work. Word is not found.
print('\nget_from_dict(my_english_dict, "galbi"):')
get_from_dict(my_english_dict, "galbi")

# Should work and print the definiton of 'kimchi'
print('\nget_from_dict(my_english_dict, "kimchi"):')
get_from_dict(my_english_dict, "kimchi")

print("\n\n###### update_word ######\n")

# Should not work. First argument should be a dict.
print('\nupdate_word("hello", "kimchi"):')
update_word("hello", "kimchi")

# Should not work. Word and definiton are required.
print('\nupdate_word(my_english_dict, "kimchi"):')
update_word(my_english_dict, "kimchi")

# Should not work. Word not found.
print('\nupdate_word(my_english_dict, "galbi", "Love it."):')
update_word(my_english_dict, "galbi", "Love it.")

# Should work.
print('\nupdate_word(my_english_dict, "kimchi", "Food from the gods."):')
update_word(my_english_dict, "kimchi", "Food from the gods.")

# Check the new value.
print('\nget_from_dict(my_english_dict, "kimchi"):')
get_from_dict(my_english_dict, "kimchi")


print("\n\n###### delete_from_dict ######\n")

# Should not work. First argument should be a dict.
print('\ndelete_from_dict("hello", "kimchi"):')
delete_from_dict("hello", "kimchi")

# Should not work. Word to delete is required.
print('\ndelete_from_dict(my_english_dict):')
delete_from_dict(my_english_dict)

# Should not work. Word not found.
print('\ndelete_from_dict(my_english_dict, "galbi"):')
delete_from_dict(my_english_dict, "galbi")

# Should work.
print('\ndelete_from_dict(my_english_dict, "kimchi"):')
delete_from_dict(my_english_dict, "kimchi")

# Check that it does not exist
print('\nget_from_dict(my_english_dict, "kimchi"):')
get_from_dict(my_english_dict, "kimchi")

# \/\/\/\/\/\/\ END DO NOT TOUCH  \/\/\/\/\/\/\

나의답~

질문 받음~

 

블로그 이미지

Or71nH

,

 

'''
Is Wed on 'days' list? True
The fourth item in 'days' is: Thu
['Mon', 'Tue', 'Wed', 'Thu','Fri', 'Sat', 'Sun', 'Sat']
['Tue', 'Wed', 'Thu', Fri', 'Sat', 'Sun', 'sat']
'''

'''
You need to create the following functions:
is_on_list
get_x
add_x
remove_x
'''


'''
DO NOT change anything inside of the "DO NOT TOUCH AREA"
해당 코드에서 빠진 함수가 있습니다. 위의 스크린과 같은 모습이 되도록 고쳐보세요.
반드시 위 표기된 함수들 (is_on_list. get_x. add_x. remove_x) 생성해야합니다.
DO NOT TOUCH 영역은 건들지마세요!
'''

퀴즈~~

"""
As you can see, the code is broken.
Create the missing functions, use default arguments.
Sometimes you have to use 'return' and sometimes you dont.
Start by creating the functions
"""

#^^^^^^^^^^^^^^^^^^^^^^^ Start ^^^^^^^^^^^^^^^^^^^^^^^^#
def is_on_list(inputlist, howdoUdo):
  if howdoUdo in inputlist:
    return True
  else:
    return False

def get_x(inputlist, howdoyoudo):
  return inputlist[howdoyoudo]

def add_x(inputlist, howUdo):
  return inputlist.append(howUdo)

def remove_x(inputlist, howyoudo):
  inputlist.remove(howyoudo)



# \/\/\/\/\/\/\  DO NOT TOUCH AREA  \/\/\/\/\/\/\ #

days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]

print("Is Wed on 'days' list?", is_on_list(days, "Wed"))

print("The fourth item in 'days' is:", get_x(days, 3))

add_x(days, "Sat")
print(days)

remove_x(days, "Mon")
print(days)


# /\/\/\/\/\/\/\ END DO NOT TOUCH AREA /\/\/\/\/\/\/\ #


 

이건 넘어가도록 하겟다~!

 

블로그 이미지

Or71nH

,

이런!! 틀렷다

 

첫날 가볍게 퀴즈 풀기~

 

블로그 이미지

Or71nH

,