Skip to content

Instantly share code, notes, and snippets.

@MorkHub
Created December 1, 2016 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MorkHub/06c2474b74d5424e2d413cadbfb8257f to your computer and use it in GitHub Desktop.
Save MorkHub/06c2474b74d5424e2d413cadbfb8257f to your computer and use it in GitHub Desktop.
largest = 0 # set largest number
number = int(input("Enter a number: ")) # get first number
while number != 0: # if number is not 0
if number > largest: # if number is greater than the biggest so far
largest = number # make the largest equal to this number
number = int(input("Enter a number: ")) # ask for next number
print("the largest number was", largest) # print the largest number
year = int(input("Enter a year (eg. 2016): ")) # get the year
month = input("Enter a month (eg. November): ").capitalize() # make the first letter a capital
leapYear = (year % 400 == 0) or (year % 4 == 0) # get the remainder from year divided by 400 and 4, if either are 0 then it is a leap year
found = False # the month has not been found yet
if month == "January" or month == "March" or month == "May" or
month == "July" or month == "August" or month =="October" or month =="December": # these months have 31 days
print("There are 31 days in",month)
found = True # the month has been found
elif month == "April" or month == "June" or month == "September" or month == "November": # these months have 30 days
print("There are 30 days in",month)
found = True # the month has been found
elif month == "February":
if leapYear:
print("There are 29 days in February")
else:
print("There are 28 days in February")
found = True # the month has been found
if not found: # if the user entered a month that does not exist
print(month,"is not a valid month.")
inStr = input("Haystack (string to search in): ")
searchChar = input("Needle (string to search for): ")
searchChar = searchChar[0] # get the first character of the string the user entered
anyFound = False # character has not been found
startAt = 0 # where to start looking
index = startAt # start looking
while index < len(inStr): # look at every character in the string
if inStr[index] == searchChar: # if current character is the character we want
anyFound = True # at least one has been found
print(searchChar, "found at position", index)
index = index + 1 # move to next character
if anyFound == False: # if we didnt find the character
print (" Sorry", searchChar, "not found")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment