1/5
## What Year Function Workshop This workshop will walk you through creating a function in Python that will take two inputs: a year and a number of days. The function will then calculate and print the year after the given number of days has passed from the beginning of the year. ### Defining the Function We'll start by defining our function, which we'll name `what_year`. This function will take two input parameters: `start_year` and `days`. ```python def what_year(start_year, days): ``` ### Calculating the Years Passed Now we'll write some code to calculate how many years have passed from the starting year based on the `days` passed. ```python def what_year(start_year, days): years_passed = days // 365 ``` ### Calculating the Target Year Next we'll write code to calculate the `target_year`. This is the year after the `days` have passed from the `start_year`. ```python def what_year(start_year, days): years_passed = days // 365 target_year = start_year + years_passed ``` ### Printing the Result Now we need to write a conditional to determine whether to print the "still" version of the sentence, or to print out the year after the days have passed. ```python def what_year(start_year, days): years_passed = days // 365 target_year = start_year + years_passed if years_passed > 0: print(f"{days} days after Jan 1st, {start_year}, it will be the year {target_year}") else: print(f"{days} days after Jan 1st, {start_year}, it will still be the year {target_year}") ``` ### Trying Out Our Function We've successfully created our What Year function. Go ahead and try it out in the Updraft code editor.
A challenging Python function workshop to determine the year. This lesson guides you through creating a function that takes two inputs: a starting year and a number of days. The function must then determine and output whether the number of days will remain in the starting year or will transition into the next year.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
Python basics
Introduction to Web3.py
Introduction to Titanoboa
Introduction to Moccasin
How to create an ERC-20
How to test Python code and Vyper smart contract
How to deploy Vyper smart contracts on ZKsync using Moccasin
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
On-chain Data Analyst
$59,000 - $139,000 (avg. salary)
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on January 14, 2025
Duration: 2h 20min
Duration: 1h 51min
Duration: 58min
Duration: 2h 23min
Duration: 53min
Duration: 2h 24min
Duration: 28min
Duration: 1h 54min
Duration: 11min
Course Overview
About the course
Python basics
Introduction to Web3.py
Introduction to Titanoboa
Introduction to Moccasin
How to create an ERC-20
How to test Python code and Vyper smart contract
How to deploy Vyper smart contracts on ZKsync using Moccasin
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
On-chain Data Analyst
$59,000 - $139,000 (avg. salary)
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on January 14, 2025
Testimonials
Read what our students have to say about this course.
Chainlink
Chainlink
Gustavo Gonzalez
Solutions Engineer at OpenZeppelin
Francesco Andreoli
Lead Devrel at Metamask
Albert Hu
DeForm Founding Engineer
Radek
Senior Developer Advocate at Ceramic
Boidushya
WalletConnect
Idris
Developer Relations Engineer at Axelar