0% found this document useful (0 votes)
83 views

Binder - Bind (Globals ) Print 'Setup Complete.'

The document defines and demonstrates functions in Python. It defines functions to add a number, calculate pay based on hours worked and tax bracket, and print a greeting without arguments or return. It calls the functions and prints their output to demonstrate their behavior. Variables are set and used as function arguments and to store return values.

Uploaded by

Hibba Tabeer
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views

Binder - Bind (Globals ) Print 'Setup Complete.'

The document defines and demonstrates functions in Python. It defines functions to add a number, calculate pay based on hours worked and tax bracket, and print a greeting without arguments or return. It calls the functions and prints their output to demonstrate their behavior. Variables are set and used as function arguments and to store return values.

Uploaded by

Hibba Tabeer
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

from learntools.

core import binder


binder.bind(globals())
from learntools.intro_to_programming.ex1 import *
print('Setup complete.')

print("Hello, world!")

# DO NOT REMOVE: Mark this question as completed


q1.check()

# TODO: Change the message


print("Your message here!")

# DO NOT REMOVE: Mark this question as completed


q2.check()

# Uncomment to get a hint


#q3.hint()

# Uncomment to view solution


#q3.solution()

# DO NOT REMOVE: Check your answer


q3.check()

# Create variables
num_years = 4
days_per_year = 365
hours_per_day = 24
mins_per_hour = 60
secs_per_min = 60

# Calculate number of seconds in four years


total_secs = secs_per_min * mins_per_hour * hours_per_day * days_per_year * num_years
print(total_secs)

# TODO: Set the value of the births_per_min variable


births_per_min = ____

# TODO: Set the value of the births_per_day variable


births_per_day = ____

# DO NOT REMOVE: Check your answer


q4.check()
# Load the data from the titanic competition
import pandas as pd
titanic_data = pd.read_csv("../input/titanic/train.csv")

# Show the first five rows of the data


titanic_data.head()

# Load the data from the titanic competition


import pandas as pd
titanic_data = pd.read_csv("../input/titanic/train.csv")

# Show the first five rows of the data


titanic_data.head()

# Number of total passengers


total = len(titanic_data)
print(total)

# Number of passengers who survived


survived = (titanic_data.Survived == 1).sum()
print(survived)

# Number of passengers under 18


minors = (titanic_data.Age < 18).sum()
print(minors)

# TODO: Fill in the value of the survived_fraction variable


survived_fraction = ____

# Print the value of the variable


print(survived_fraction)

# TODO: Fill in the value of the minors_fraction variable


minors_fraction = ____

# Print the value of the variable


print(minors_fraction)

# DO NOT REMOVE: Check your answer


q5.check()

# Uncomment to receive a hint


#q5.hint()

# Uncomment to view the solution


#q5.solution()
# Define the function
def add_three(input_var):
output_var = input_var + 3
return output_var

# Run the function with 10 as input


new_number = add_three(10)

# Check that the value is 13, as expected


print(new_number)

def get_pay(num_hours):
# Pre-tax pay, based on receiving $15/hour
pay_pretax = num_hours * 15
# After-tax pay, based on being in 12% tax bracket
pay_aftertax = pay_pretax * (1 - .12)
return pay_aftertax

# Calculate pay based on working 40 hours


pay_fulltime = get_pay(40)
print(pay_fulltime)

pay_parttime = get_pay(32)
print(pay_parttime)

print(pay_aftertax)

def get_pay_with_more_inputs(num_hours, hourly_wage, tax_bracket):


# Pre-tax pay
pay_pretax = num_hours * hourly_wage
# After-tax pay
pay_aftertax = pay_pretax * (1 - tax_bracket)
return pay_aftertax

higher_pay_aftertax = get_pay_with_more_inputs(40, 24, .22)


print(higher_pay_aftertax)

same_pay_fulltime = get_pay_with_more_inputs(40, 15, .12)


print(same_pay_fulltime)
# Define the function with no arguments and with no return
def print_hello():
print("Hello, you!")
print("Good morning!")

# Call the function


print_hello()

You might also like