computer science
average.py
#!/usr/bin/env python round1 = int(input("Enter score for round 1: ")) round2 = int(input("Enter score for round 2: ")) round3 = int(input("Enter score for round 3: ")) average = (round1 + round2 + round3) / 3 print ("the average score is: ", average)
login.py
#!/usr/bin/env python username = input("Login: >> ") user1 = "Jack" user2 = "Jill" if username == user1: print("Access granted") elif username == user2: print("Welcome to the system") else: print("Access denied")
reddit-bots-master.zip
reddit-bots-master/LICENSE.md
This software is licensed under the MIT license. MIT license ----------- Copyright © 2010 [Elijah Grey][1], who also goes by [Eli Grey][1]. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. [1]: http://eligrey.com
reddit-bots-master/README.md
Reddit Bots =========== A collection of various reddit bots. Reddit Feeds Auto-Poster ------------------------ Reddit Feeds Auto-Poster is a Python script that automatically posts new entries from feeds to a subreddit. Coming soon! (in Valve time) Reddit Self Posts Copier ------------------------ Reddit Self Posts Copier is a Python script that copies self posts from one or more subreddit to a target subreddit. ### Usage reddit-self-posts-copier.py [options] ### Options <dl> <dt><code>--version</code></dt> <dd>show program's version number and exit</dd> <dt><code>-h</code>, <code>--help</code></dt> <dd>show this help message and exit</dd> <dt><code>-u USERNAME</code>, <code>--username=USERNAME</code></dt> <dd>username for bot to login as</dd> <dt><code>-p PASSWORD</code>, <code>--password=PASSWORD</code></dt> <dd>password for the username</dd> <dt><code>-r SUBREDDIT</code>, <code>--subreddit=SUBREDDIT</code></dt> <dd>subreddits to copy from; can specify multiple</dd> <dt><code>-t SUBREDDIT</code>, <code>--target=SUBREDDIT</code></dd> <dd>target subreddit</dd> <dt><code>-v</code>, <code>--verbose</code> (enabled by default)</dt> <dd>show informative messages</dt> <dt><code>-q</code>, <code>--quiet</code></dt> <dd>hide informative messages</dd> <dt><code>-m</code>, <code>--manual</code> (disabled by default)</dt> <dd>enable manual screening of submissions</dd> <dt><code>-s SITE</code>, <code>--site=SITE</code> (defaults to <code>http://www.reddit.com/</code>)</dt> <dd>target reddit-powered site</dd> <dt><code>-f FILE</code>, <code>--save-file=FILE</code> (defaults to <code>.submitted</code>)</dt> <dd>file to save the submitted posts to</dd> <dt><code>-l LIMIT</code>, <code>--limit=LIMIT</code> (defaults to <code>25</code>)</dt> <dd>amount of submissions to poll for</dd> <dt><code>-o POLL_RATE</code>, <code>--poll-rate=POLL_RATE</code> (defaults to <code>120</code>)</dt> <dd>rate in seconds at which to poll for new submissions</dd> <dt><code>-e SUBMIT_RATE</code>, <code>--submit-rate=SUBMIT_RATE</code> (defaults to <code>4</code>)</dt> <dd>rate in seconds at which to post new submissions</dd> </dl> 
reddit-bots-master/reddit-self-posts-copier.py
#!/usr/bin/env python3 # -*- coding: UTF-8 -*- '''Reddit Self Posts Copier. Copies self posts from one or more subreddit to a target subreddit.''' # By Eli Grey, http://eligrey.com # License: The MIT license (see LICENSE.md) from sys import stdout, stdin from urllib import request as urlrequest from urllib import parse as urlparse from urllib import error as urlerror from http import cookiejar from time import sleep import json import re VERSION = '2010-06-09' APP_TITLE = 'Reddit Self Posts Copier' USER_AGENT = {'User-agent': APP_TITLE + '/' + VERSION} def request_json(request): try: return json.loads(urlrequest.urlopen(request).read().decode('utf-8')) except (urlerror.URLError, KeyError, ValueError): return None def unescape_entities(html): left_bracket = re.compile('<', re.IGNORECASE) right_bracket = re.compile('>', re.IGNORECASE) ampersand = re.compile('&', re.IGNORECASE) return ampersand.sub('&', right_bracket.sub('>', left_bracket.sub('<', html))) class Title: def set(self, title): self.title = title stdout.write('\x1b]2;' + title + '\x07') def get(self): return self.title class RedditInvalidUsernamePasswordException(Exception): pass class SubredditSubmissionsCopier: def __init__(self, options, submitted): self.options = options self.submitted = submitted self._maybe_down_message = 'Perhaps the connection was interupted or %s is down.' % self.options.site cookie_jar = cookiejar.FileCookieJar() urlrequest.install_opener(urlrequest.build_opener(urlrequest.HTTPCookieProcessor(cookie_jar))) def login(self): params = urlparse.urlencode({ 'user': self.options.username, 'passwd': self.options.password }) request = urlrequest.Request(self.options.login_url, params, USER_AGENT) if self.options.verbose: print('Logging in as %s.' % self.options.username) response = request_json(request) if response is None or 'invalid password' in str(response): raise RedditInvalidUsernamePasswordException('Login failed. Please ensure that your username and password are correct.') title.set('%s - %s' % (self.options.target, APP_TITLE)) def submit(self, submission, modhash): self.submitted.append(submission['id']) try: open(self.options.save_file, 'a').write('\n' + submission['id']) except IOError: if self.options.verbose: print('Problem saving submission %s.' % submission['id']) submission_title = unescape_entities(submission['title']) if self.options.manual: normal_title = title.get() title.set('[!] ' + normal_title); print('Submit %r from %s (Y/N)?' % (submission_title, submission['subreddit'])) approved = stdin.readline()[0].upper() title.set(normal_title) if approved != 'Y': return elif self.options.verbose: print('Submitting %r from %s.' % (submission_title, submission['subreddit'])) params = urlparse.urlencode({ 'title': submission_title, 'text': unescape_entities(submission['selftext']), 'kind': 'self', 'sr': self.options.target, 'uh': modhash }) request = urlrequest.Request(self.options.submit_url, params, USER_AGENT) response = request_json(request) if self.options.verbose: if '.error.BAD_CAPTCHA.field-captcha' in str(response): print('Could not submit the post because a CAPTCHA was required.') elif '.error.RATELIMIT.field-ratelimit' in str(response): print('Could not submit the post because a submission rate limit was triggered.') elif response is None: print('Problem submitting the post.' + self._maybe_down_message) def poll(self): if self.options.verbose: print('Polling for new submissions.') request = urlrequest.Request(self.options.poll_url, headers=USER_AGENT) submissions = request_json(request) if submissions is not None: modhash = submissions['data']['modhash'] submissions = submissions['data']['children'] for submission in submissions: if submission['data']['is_self'] and submission['data']['id'] not in submitted: sleep(self.options.submit_rate) self.submit(submission['data'], modhash) if __name__ == '__main__': from optparse import OptionParser parser = OptionParser(version=APP_TITLE + ' ' + VERSION) parser.add_option('-u', '--username', dest='username', help='username for bot to login as', metavar='USERNAME') parser.add_option('-p', '--password', dest='password', help='password for the username', metavar='PASSWORD') parser.add_option('-r', '--subreddit', dest='subreddits', help='subreddits to copy from; can specify multiple', metavar='SUBREDDIT', action='append') parser.add_option('-t', '--target', dest='target', metavar='SUBREDDIT', help='target subreddit') parser.add_option('-v', '--verbose', dest='verbose', default=True, metavar='VERBOSE', action='store_true', help='show informative messages') parser.add_option('-q', '--quiet', dest='verbose', metavar='VERBOSE', action='store_false', help='hide informative messages') parser.add_option('-s', '--site', dest='site', metavar='SITE', help='target reddit-powered site', default='http://www.reddit.com/') # yeah, I sold out to reddit.com parser.add_option('-f', '--save-file', dest='save_file', metavar='FILE', default='.submitted', help='file to save the submitted posts to') parser.add_option('-l', '--limit', dest='limit', metavar='LIMIT', type='int', help='amount of submissions to poll for', default=25) parser.add_option('-o', '--poll-rate', dest='poll_rate', default=120, type='float', metavar='POLL_RATE', help='rate in seconds at which to poll for new submissions') parser.add_option('-e', '--submit-rate', dest='submit_rate', default=4, type='float', metavar='SUBMIT_RATE', help='rate in seconds at which to post new submissions') parser.add_option('-m', '--manual', dest='manual', default=False, action='store_true', metavar='ENABLE_MANUAL', help='enable manual screening of submissions') (options, args) = parser.parse_args() options.poll_url = options.site + 'r/%s/hot.json?limit=%d' % ('+'.join(options.subreddits), options.limit) options.login_url = options.site + 'api/login' options.submit_url = options.site + 'api/submit' try: submitted = open(options.save_file, 'r').read().split('\n') if options.verbose: print('Loaded ' + options.save_file) except IOError: submitted = [] title = Title() title.set(APP_TITLE) copier = SubredditSubmissionsCopier(options, submitted) copier.login() try: while True: copier.poll() sleep(options.poll_rate) except KeyboardInterrupt: if options.verbose: print('Closing %s.' % APP_TITLE) quit()
conversion.py
#!/usr/bin/env python kmh = int(input("Enter km/h: ")) mph = 0.6214 * kmh print("Speed:", kmh, "KM/H = ", mph, "MPH")
CSS 225 Python Guide.docx
This guide covers how to launch Python in the following: lab, on a Windows machine, and on a Mac.
This guide also covers how to launch the Python editor IDLE and how to run a Python program.
In the lab or on a Windows machine:
1 - Open Chrome .
2 - You should see the AppsAnywhere icon below the web address bar: or go to the following: https://appsanywhere.nl.edu/
3 – Login using your NLU username and password.
4 – Launch Python:
5 – Open Cloudpaging Player:
6 – Launch Python 3.7.0:
Open a New File:
1 - Run Start > Python > IDLE(Python 3.7 64-bit)
2 – File > New File
Edit a Python File:
1 - Run Start > Python > IDLE(Python 3.7 64-bit)
2 – File > Open > Find file to open
Run a Python Script:
1 – Run > Run Module or (F5)
Module 1 Lab Activity.docx
Module 1: Lab Activity - Commenting and Documentation
Submission:
1 – Program files for conversion.py, login.py, and average.py
2 – New document with answers to Part 2
Practice Commenting:
The simplest way to start writing more comments is just to do it!
Comments are created in Python using the pound sign (#) and should be brief statements no longer than a few sentences. Here’s a simple example:
# This is a comment
“””This is a docstring”””
According to the Python Style Guide PEP8 the maximum line length for comments should be 72 characters.
Tips
1. Keep comments as close to the code being described as possible. Comments that aren’t near their describing code are frustrating to the reader and easily missed when updates are made.
2. Don’t use complex formatting (such as tables or ASCII figures). Complex formatting leads to distracting content and can be difficult to maintain over time.
3. Don’t include redundant information. Assume the reader of the code has a basic understanding of programming principles and language syntax.
4. Design your code to comment itself. The easiest way to understand code is by reading it. When you design your code using clear, easy-to-understand concepts, the reader will be able to quickly conceptualize your intent.
Part 1: Start writing comments for yourself in code. Make it a point to include simple comments from now on where necessary.
1 - Download conversion.py from D2L > Module 1: Introduction to Programming > Module 1: Lab Activity – Commenting and Documentation.
- Open with a text editor (Not Word) or Python IDLE.
- What do you think this program does? Can you easily tell what’s going on without any commenting?
- Let’s run the program and see if we were correct.
- Based on observation, add comments to the program to:
A – give authorship
B – give a date for last edit (today)
C – give a simple explanation of what the program does
D – comment on anything else that might be helpful to you or someone else looking at this code
2 - Do the same for login.py and average.py
Practice Documentation:
A README is often the first item a visitor will see when visiting your repository. README files typically include information on:
· What the project does
· Why the project is useful
· How users can get started with the project
· Where users can get help with your project
· Who maintains and contributes to the project
A thorough README includes:
· Project Title
· Motivation
· Build Status
· Code Style
· Screenshots
· Tech/framework Used
· Features
· Code Example
· Installation
· API Reference
· Tests
· How to use?
· Contribute
· Credits
· License
Part 2: Review some ReadMe files. Answer the questions below.
3 - Let’s look at a ReadMe file - https://github.com/sinwar/flaskr
- Open the README.md file by clicking on it.
- Does this README clearly include the information above? If not, what is it missing?
4 - Download RedditBot-master from D2L > Module 1: Introduction to Programming > Module 1: Lab Activity – Commenting and Documentation.
- Extract all files
- Open the README.md file with a text editor (Not Word)
- Does this README clearly include the information above? If not, what is it missing?