This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """Creates a histogram of the word lengths from the text file""" | |
| import sys | |
| def read_text(): | |
| inputF = open(sys.argv[1], 'r') | |
| return inputF | |
| openF = read_text() | |
| text = openF.read() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ Exception handling while dividing integers""" | |
| while True: | |
| integer = input("Provide an integer: ") | |
| try: | |
| print(10/int(integer)) | |
| except ValueError: | |
| print("Your input must be an integer") | |
| except ZeroDivisionError: | |
| print("Your input must not be zero") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ A program to change case using functions """ | |
| import sys | |
| def caps_case(text): | |
| """Returns the 1st character capitalized""" | |
| print(text.capitalize()) | |
| def title_case(text): | |
| """Returns the 1st letter of all words capitalized""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| s = input("Enter a sentence for testing: ") | |
| if s.isupper() and s.endswith("."): | |
| print("Perfect! Input meets both requirements") | |
| elif s.isupper() and not s.endswith("."): | |
| print("Input doesn't end with a period") | |
| elif not s.isupper() and s.endswith("."): | |
| print("Input is not all upper-case") | |
| else: | |
| print("Please re-enter a sentence that satisfies both the requirements") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def myfunc(string): | |
| str = '' | |
| index =0 | |
| for l in string: | |
| if index %2 ==0: | |
| str = str + l.lower() | |
| index +=1 | |
| else: | |
| str = str + l.upper() | |
| index +=1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #SAMPLE CODE FOR SPATIAL PATTERNS OF VARIABLES | |
| library(ggplot2) | |
| library(fiftystater) | |
| bachdeg <- read.csv("C:/Users/DASA0/Desktop/Stat 524/Project/bachdeg.csv", sep=",") | |
| bachdeg$state <- tolower(bachdeg$State) | |
| # map_id creates the aesthetic mapping to the state name column in your data | |
| p <- ggplot(bachdeg, aes(map_id = state)) + | |
| # map points to the fifty_states shape data | |
| geom_map(aes(fill = bachdeg), map = fifty_states) + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def check_prime(nums): | |
| if num <2: | |
| return 0 | |
| myprimelist = [2] | |
| j = 3 | |
| while j <=num: | |
| for i in range(j,3,2): | |
| if j % i ==0: | |
| j += 2 | |
| break |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mlist = [] | |
| for x in range(1, 1000): | |
| if x %3 ==0 and x % 5 ==0: | |
| mlist.append(x) | |
| elif x % 3 ==0: | |
| mlist.append(x) | |
| elif x % 5==0: | |
| mlist.append(x) | |
| print(sum(mlist)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fiblist = [] | |
| a,b=1,2 | |
| while b < 8000001: | |
| fiblist.append(a) | |
| a,b = b,a+b | |
| print(fiblist) | |
| newlist = [] | |
| for num in fiblist: | |
| if num % 2 ==0: | |
| newlist.append(num) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def max_prime_factor(n): | |
| i = 2 | |
| pfactors = [] | |
| while i * i <= n: | |
| if n % i: | |
| i += 1 | |
| else: | |
| n //= i | |
| pfactors.append(i) | |
| if n > 1: |