Skip to content

Instantly share code, notes, and snippets.

@gitaficionado
gitaficionado / ProcesingAList.py
Created March 11, 2021 16:43
Create a new program in Repl.it called "Lists." Your goal for this program is to create sections of code that will perform different outputs with the list called, names which contains the following values - Peter, Bruce, Steve, Tony, Natasha, Clint, Wanda, Hope, Danny, Carol and the list called numbers which contains the following values - 100, …
'''
Create a new program in Repl.it called "Lists." Your goal for this program is to create sections of code that will perform different
outputs with the list called, names which contains the following values - Peter, Bruce, Steve, Tony, Natasha, Clint, Wanda, Hope,
Danny, Carol and the list called numbers which contains the following values - 100, 50, 10, 1, 2, 7, 11, 17, 53, -8, -4, -9, -72, -64,
-80. At the beginning of your program, add in any comments and create the two lists. Then create the following:
A loop that will output every other name in the names list.
A loop that will output only the positive numbers in the numbers list.
A loop that will output the sum of all the values in the numbers list.
A loop that will output only the numbers that are odd.
@gitaficionado
gitaficionado / RangeTester.py
Created March 11, 2021 16:36
Prompt the user for a number from 1 to 100. Using a while loop, if they entered an invalid number, tell them the number entered is invalid and then prompt them again for a number from 1 to 100. If they enter a valid number - thank them for their input.
'''
1. Prompt the user for a number from 1 to 100. Using a while loop, if they entered an invalid number, tell them the number entered is invalid and then prompt them again for a number from 1 to 100. If they enter a valid number - thank them for their input.
Prompt the user for a number from 1 to 100
While that number is less than 1 or that number is more than 100
Output that they entered an invalid number
Prompt them again for a number from 1 to 100
Output to the user, thanking them for their input
'''
@gitaficionado
gitaficionado / ColorGuess.py
Created March 11, 2021 16:32
Prompt the user to guess your favorite color. Using a while loop, if the user didn't guess your favorite color [pick one for this activity] then tell them they are incorrect, then ask them again. Whenever they guess the color correctly, output that they are correct and how many guesses it took them.
'''
2. Prompt the user to guess your favorite color. Using a while loop, if the user didn't guess your favorite color [pick one for this activity] then tell them they are incorrect, then ask them again. Whenever they guess the color correctly, output that they are correct and how many guesses it took them.
Create a variable and assign it the value of 1
Prompt the user to guess your favorite color
While their guess is not equal to your favorite color
Tell them they are incorrect
Prompt them to guess again
Add one to the variable above
Output to the user, they were correct and how many attempts it took using the variable
@gitaficionado
gitaficionado / SumNumbers.py
Created March 11, 2021 16:29
Ask the user how many numbers for which they want to calculate the sum. Using a for loop, prompt the user to enter that many numbers, one-by-one, keeping track of the sum. At the end, after the user entered all numbers, output the sum.
'''
3. Ask the user how many numbers for which they want to calculate the sum. Using a for loop, prompt the user to enter that many numbers, one-by-one, keeping track of the sum. At the end, after the user entered all numbers, output the sum.
Create a variable and assign it the value of 0
Prompt the user for how many numbers they have
With a for loop, set it to repeat enough times to get all their values
Prompt the user for a number
Add that number to the variable that started as 0
Output to the user, the sum of all values
@gitaficionado
gitaficionado / StringStatsArray.java
Created March 9, 2021 20:34
Beginning code for StringStatsArray class
import java.util.Scanner;
public class StringStatsArray{
private final String[] arr;
public StringStatsArray(String[] a){
arr = a;
}
@gitaficionado
gitaficionado / NumStatsArray.java
Created March 9, 2021 20:13
Beginning structure of NumStatsArray
public class NumStatsArray{
//Create a private array as a double as final
________________________________________
public NumStatsArray(double[] a){
arr = a;
}
//Iterate through and cancatenate all values except last and follow each with a comma. Creat string with a "{" the beginning and end it with a "}".
@gitaficionado
gitaficionado / NumStatsArray.java
Last active March 9, 2021 21:29
Use the following java file to begin your NumStatsArray class.
public class NumStatsArray{
//Create a private array as a double as final
________________________________________
public NumStatsArray(double[] a){
arr = a;
}
/* Iterate through and cancatenate all values except last and follow each with a comma.
@gitaficionado
gitaficionado / VehicleDemo.java
Created February 4, 2021 15:18
Create a class named Vehicle that simulates a car moving along a 40 block stretch of road. Your class will build a vehicle and keep track of its location on the road. Location values may range from -20 to 20. A location value of 0 represents block 0, a location value of 1 represents block 1, a location value of 2 represents block 2, etc. If the …
public class Vehicle
{
//private integer to store the vehicle's location
private int __________;
public ________()
{
location = ___;
}
@gitaficionado
gitaficionado / .java
Last active January 7, 2021 15:25
The String Shortener assignment requires students to write a short program in Java to shorten messages by removing duplicate letters and vowels.
import java.util.Scanner;
class StringShortener {
public static void main(String[] args) {
//Declare scanner
Scanner scan = new Scanner(System.in);
//Get message from user input
System.out.println("Type the message to be shortened");
String msg = scan.nextLine();
@gitaficionado
gitaficionado / Day1.java
Created December 9, 2020 19:22
AOC 2020 day 1 for demo. Thanks to TurkeyDev for the file
package dev.theturkey.aoc2020;
import java.util.List;
public class Day1 extends AOCPuzzle
{
public Day1()
{
super("1");
}