Skip to content

Instantly share code, notes, and snippets.

View vereperrot's full-sized avatar
😀
Out sick

vere perrot vereperrot

😀
Out sick
View GitHub Profile
@vereperrot
vereperrot / print_full_name.py
Created April 28, 2020 12:41
print_full_name.py
def get_formatted_name(first_name,last_name):
"""return full name"""
full_name=first_name+' '+last_name
return full_name.title()
def print_full_name():
while True:
print("\nPlease tell me your name:")
print("(enter 'q' at any time to quit)")
f_name=input("First name:")
if f_name=='q':
@vereperrot
vereperrot / build_person.py
Created April 28, 2020 12:39
build_person.py
def build_person(first_name,last_name,age=''):
"""return a dictionary, its about a person's information"""
person={'first':first_name,'last':last_name}
if age:
person['age']=age
return person
musician=build_person('jimi','hendrix',age=27)
print(musician)
"""
OUTPUT:
@vereperrot
vereperrot / describe_city.py
Created April 28, 2020 12:37
describe_city.py
def describe_city(city,country="Taiwan"):
if city is "Tainan" or city is "Taipei":
print("\n "+city+" is in "+country)
else:
print("\n "+city+" is not in "+country)
describe_city(city="Tainan")
describe_city(city="Taipei")
describe_city(city="New York")
"""
OUTPUT:
@vereperrot
vereperrot / make_shirt.py
Created April 28, 2020 12:32
make_shirt.py
def make_shirt(size,text="I love Python"):
print("\n The shirt size is "+size+".")
print("\n The shirt text is "+text+".")
make_shirt(size="big")
make_shirt(size="medium",text="Python is good")
"""
OUTPUT:
The shirt size is big.
The shirt text is I love Python.
@vereperrot
vereperrot / describe_pet.py
Created April 28, 2020 12:24
describe_pet
def describe_pet(pet_name,animal_type='dog'):
"""show pet information"""
text="\n I have a "+animal_type+"."
text+="\n My "+animal_type+"'s name is "+pet_name.title()+"."
print(text)
return text
describe_pet(pet_name="harry")
"""
OUTPUT:
I have a dog.
@vereperrot
vereperrot / access webcam.py
Created December 24, 2019 08:56
access webcam.py
import cv2
cv2.namedWindow("preview")
vc = cv2.VideoCapture(0)
if vc.isOpened(): # try to get the first frame
rval, frame = vc.read()
else:
rval = False
@vereperrot
vereperrot / print list.py
Created December 19, 2019 09:03
print list
# https://stackoverflow.com/questions/4440516/in-python-is-there-an-elegant-way-to-print-a-list-in-a-custom-format-without-ex
lst = [[1, 2],[ 3,4]]
>>> print('\n'.join('{}: {}'.format(*k) for k in enumerate(lst)))
0: [1, 2]
1: [ 3,4]
@vereperrot
vereperrot / list contains.py
Created December 19, 2019 08:57
list contains.py
#https://stackoverflow.com/questions/12934190/is-there-a-short-contains-function-for-lists
if myItem in list:
# do something
#Also, inverse operator:
if myItem not in list:
# do something
@vereperrot
vereperrot / user input.py
Last active December 19, 2019 09:01
user input
# python 3
# https://stackabuse.com/getting-user-input-in-python/
# https://www.geeksforgeeks.org/python-output-formatting/
txt = input("Type something to test this out: ")
print("Is this what you just said? %s"%( txt))
@vereperrot
vereperrot / read specific frame using VideoCapture.py
Created December 19, 2019 08:55
read specific frame using VideoCapture
# https://stackoverflow.com/questions/33650974/opencv-python-read-specific-frame-using-videocapture
import numpy as np
import cv2
cap = cv2.VideoCapture(video_name) #video_name is the video being called
cap.set(1,frame_no); # Where frame_no is the frame you want
ret, frame = cap.read() # Read the frame
cv2.imshow('window_name', frame) # show frame on window
#If you want to hold the window, until you press exit:
while True: