Sunday, 100 days of Trick Your Branin with the 20min Rule, Code for a Purpose Have a Project, There is no perfect language to learn, Understand what you are writing, It's OK to No Know, Be a Copycat, Be accountable to someone Show your work, Keep Learning, Play Foosball, Get a mentor - Try Pair Programming, Get into the Habit of Chunking, Break someone else's code

Day 1

print("Welcome to the Band Name Generator.")
street = input("What's name of the city you grew up in?\n")
pet = input("What's your pet's name?\n")
print("Your band name could be " + street + " " + pet)
  • assignment day1
#Write your code below this line 👇
print("Day 1 - Python Print Function")
print("The function is declared like this:")
print("print('what to print')")























#Write your code above this line 👆
# 🚨 Do NOT modify the code below this line 👇
with open("testing_copy.py", "w") as file:
  file.write("def test_func():\n")
  with open("main.py", "r") as original:
    f2 = original.readlines()[0:8]
    for x in f2:
      file.write("    " + x)

import testing_copy
import unittest
from unittest.mock import patch
from io import StringIO
import os

class MyTest(unittest.TestCase):
  def test_1(self): 
    with patch('sys.stdout', new = StringIO()) as fake_out: 
      testing_copy.test_func()
      expected_print = "Day 1 - Python Print Function\nThe function is declared like this:\nprint('what to print')\n"
      self.assertEqual(fake_out.getvalue(), expected_print) 

print("\n\n")
print('Checking if what you printed matches the target output *exactly*...')
print('Running some tests on your code:')
print(".\n.\n.\n.")
unittest.main(verbosity=1, exit=False)

os.remove("testing_copy.py") 

The following wiki, pages and posts are tagged with

TitleTypeExcerpt