ASCII – American Standard Code for Information Interchange
The ascii() function returns a string containing a printable representation of an object and escapes the non-ASCII characters in the string using \x, \u or \U escapes.
Syntax
ascii(object)
object - String , List , tuple etc.
Ex.
list = ['P¥thon' , 'µ', ' CodË it']
print(ascii(list))
The any() function returns True if any item in an iterable are true. If no item is true then False.
Syntax & Parameters
any(iterable)
iterable – An iterable object list, tuple, dictionary etc.
Ex.
# 1 is True , 0 is False
mList = [1, 1, 0]
print(any(mList))
# The any() function checks the keys, not the values in dictionaries.
mDict = {0 : "Car", 1 : "Truck"}
print(any(mDict))
# True
mStr = "this is a string"
print(any(mStr))
Progress Dialog is dialog showing a progress indicator and an optional text message or view. The methods of Progress Dialog being used in this tutorial are: ProgressDialog.setTitle() – Used to set title of dialog box ProgressDialog.setMessage() – Used to set dialog message being displayed ProgressDialog.setProgressStyle() – Choose the style of indicator ProgressDialog.dismiss() – Dismiss the…
SeekBar is an extension of ProgressBar that adds a draggable thumb. The user can touch thumb and drag left or right to set the current progress level or various other task. In this example, the seekbar will be used to display a percentage. As the user moves the SeekBar left to right the percentage value…
This tutorial will show how to interact with the Ethereum blockchain using Python. To start, the Python library Web3 will need to be installed. The Web3 library allows you to interact with a local or remote Ethereum node, using a HTTP or IPC connection. Using Web3 you will be able to create smart contracts on…
This tutorial will show how to make a magic 8 ball program in python. This program will have the same functions as a magic 8 ball , the user will input a question and the 8-ball will generate a reply to the question.
The user’s input will by retrieved by using input() . Here is a link to a quick tutorial on the input() keyword in Python.
# Import modules
import sys
import random
reply = True #If running
while reply:
inputQuestion = input("Type 'quit' to exit... Ask magic 8 ball a question: ")
response = random.randint(1, 8)
if inputQuestion == "quit":
sys.exit() #exit program
# List of random responses
elif response == 1:
print("It is certain")
elif response == 2:
print("Don't count on it.")
elif response == 3:
print("Yes.")
elif response == 4:
print("Ask again later")
elif response == 5:
print("Concentrate and ask again")
elif response == 6:
print("Reply hazy, try again")
elif response == 7:
print("As I see it, yes.")
elif response == 8:
print("It will not be so.")
Output:
Type 'quit' to exit..Ask magic 8 ball a question: will i pass my test?
It is certain
The chr() function returns a character that represents the specified unicode. Syntax chr(i) The chr() method takes only one integer as argument.The range may vary from 0 to 1,1141,111(0x10FFFF in base 16).The chr() method returns a character whose unicode point is num, an integer.If an integer is passed that is outside the range then the method returns…
The callable() method checks if a object is callable. Callable objects are True if object is callable and False if object is not callable. Syntax & Parameters callable(object) The callable() method takes one argument, an object and returns one of the two values: returns True, if the object appears to be callable.returns False, if the…
bytes() returns an immutable bytes object, made up of a sequence of integers in the range 0 <=x < 256. The returned bytes sequence is immutable. A mutable bytes sequence can be used instead by calling is bytearry() . Syntax bytes(]]) bytes() takes three optional parameters: source – initialize the array of bytes. Can be String…
This tutorial will show how to make a simple java program that will count how many day there are till Christmas. The package being used to handle the dates is java.time . If you are unfamiliar with this package here is a quick intro on how to use the package.
The Christmas Count-down Clock code works like this. The today variable gets today’s date
Variable ChristmasDay is set to December 25 2020, which is this years Christmas.
Note that if Christmas has already past for this year, the Years() in java.time is given a 1 to represent Christmas being a Full year away from the current date.
Variable p gets the difference between today’s date and next years Christmas
import java.time.LocalDate;// importing LocalDate class
import java.time.Month;// importing Month class
import java.time.Period;// importing Period class
import java.time.temporal.ChronoUnit;// importing ChronoUnit class
public class aaa {
public static void main(String[] args) {
LocalDate today = LocalDate.now();//getting current date
LocalDate ChristmasDay = LocalDate.of(2020, Month.DECEMBER, 25);// setting Christmass day
LocalDate nextXmas = ChristmasDay.withYear(today.getYear());// Next year Christmas
//Add 1 if Christmas has past this year
if (nextXmas.isBefore(today) || nextXmas.isEqual(today)) {
nextXmas = nextXmas.plusYears(1);
}
Period p = Period.between(today, nextXmas);
long p2 = ChronoUnit.DAYS.between(today, nextXmas);// nanoseconds in days till Christmas
System.out.println("There are " + p.getMonths() + " months, and " +
p.getDays() + " days until Christmas! (" +
p2 + " total)");
}
}
Output :
There are 0 months, and 19 days until Christmas! (19 total)
The bytearray() method returns an array of bytes. Syntax bytearray(]]) source – source to initialize the array of bytes string – Converts the string to bytes using str.encode()integer – Creates an array of provided size, all initialized to nulliterable – Creates an array of size equal to the iterable count . Iterable integers must be…
The breakpoint() function is a debugging function that is built into Python 3.7 . Use this built in function by adding breakpoint() where you suspect the error or are wanting to check for bugs. The pdb (Python Debugger) is a interactive source code debugger for Python programs. Python Debugger Commands : Ex. Output Once code…
The bool() function converts a value to a Boolean expression, True or False . If no parameter is given, by default the Boolean returns False. Boolean returns True if the parameter or value is True. Syntax bool([x]) x – is the value being evaluated by standard truth testing procedures. Example Output
This tutorial will show how to create a time stamp with Java. Since Java does not have a built in package for handing dates and time, the package java.time will need to be imported. This package is an API for dates, times, instants, and durations. Here is a link to the java.time documentation if you would like more detail.
Here are five of the most useful classes that come with java.time :
Class
Description
LocalDate
Current date(year,month,day)
LocalTime
Current time (8:30 am)
LocalDateTime
Current date & time ()
Instance
Creates a Time Stamp
ZoneDateTime
Current date & time with time-zone
import java.time.LocalDate;// importing LocalDate class
import java.time.Instant;//importing Instant class
public class Example{
public static void main(String[] args) {
LocalDate current = LocalDate.now();
Instant timeStamp = Instant.now();
System.out.println(current); // Print out current date
System.out.println(timeStamp); // Print out Time Stamp
}
}
Output
Current Date : 2020-12-03
Time Stamp : 2020-12-03T21:06:58.325913800Z
java.time has other classes that allow dates to be moved durations and periods. Durations are movements on a time line in nanoseconds and Periods are movements like days, years or months.
The package comes with the built in keyword .plus() . This can be used to move incrementally forward in a timeframe .
.plusYears()
Move a given # of Years
.plusDays()
Move a given # of Days
.plusWeeks()
Move a given # of Weeks
.plusMoths()
Move a given # of Moths
java.time also comes with .minus() . This can be used to move incrementally backwards in a timeframe.
.minusDays()
Subtract a given # of Days
.minusWeeks()
Subtract a given # of Weeks
.minusMoths()
Subtract a given # of Moths
.minusYears()
Subtract a given # of Years
import java.time.LocalDate;// importing LocalDate class
public class Example{
public static void main(String[] args) {
LocalDate future = LocalDate.now().plusDays(300);//getting current date and add 300 days
LocalDate past = LocalDate.now().minusDays(100);// minus 100 days from today
LocalDate next = LocalDate.now().plusMonths(1);// Next month from today
System.out.println(future);
System.out.println(past);
System.out.println(next);
}
}
ASCII – American Standard Code for Information Interchange The ascii() function returns a string containing a printable representation of an object and escapes the non-ASCII characters in the string using \x, \u or \U escapes. Syntax ascii(object) object – String , List , tuple etc. Ex. Output :
The any() function returns True if any item in an iterable are true. If no item is true then False. Syntax & Parameters any(iterable) iterable – An iterable object list, tuple, dictionary etc. Ex. Output :
To get the users input the module Scanner must be imported. Scanner is built into the java.util package and is used for retrieving inputted datatypes. Here is a link to the Scanner documentation for a more in detail explanation for the package.
import java.util.Scanner; // import the Scanner
class aaa {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
//Variables
String Name;
String Last;
// Enter first & last name
// Press Enter after
System.out.println("Enter First & Last Name");
Name = input.nextLine();
Last = input.nextLine();
System.out.println("Full Name is: " + Name + " " + Last);
}
}
Output:
Enter First & Last Name
code
it
Full Name is: code it
Its important to note that Scanner accepts different input types. For this example, notice the line input.nextLine()
nextLine() is a keyword that tells Scanner that the user is inputting a String. In the table below are a some commonly used Input types.
The all() function returns Ture if all elements are itterable and False if elements are not. Parameters all(iterable) iterable – is an object that can be looped over such as list , string , tuple etc. Ex. Output :
# 1 What’s Pickling and Unpickling? Pickling – the process of a Python object hierarchy being converted into a byte streamUnpickling – is the inverse operation, where a byte stream is converted back into an object hierarchy. Pickling is also called serialization, marshalling, or flattening. # 2 What Is the Difference Between range() and xrange() Functions in Python?…
This will show how to read key strokes from a keyboard using Python. First, the python library Curses must be imported, here is a link to the curses documentation if you would like more in-depth detail. Curses is is used to read key strokes from keyboard and set different actions for each key.
In this example, the Up, Down, Left and Right keys on the keyboard will be used. When a the program is ran, what ever directional key is being pressed will be printed in the terminal. It is important to know that the python file must be executed in the computer terminal. The curses library will not run in a IDE. Use the command sudo python File_Name.py
import curses
#Get Window
screen = curses.initscr()
# Turn off Echo
curses.noecho()
#Instant Response
curses.cbreak()
#Use Special Keys
screen.keypad(True)
try:
while True:
char = screen.getch()
#if 'q' is pressed
if char == ord('q'):
break
#If UP Key is pressed
elif char == curses.KEY_UP:
print("UP Key")
#If Down Key is pressed
elif char == curses.KEY_DOWN:
print("DOWN Key")
#If LeftKey is pressed
elif char == curses.KEY_LEFT:
print("LEFT Key")
#If Right Key is pressed
elif char == curses.KEY_RIGHT:
print("RIGHT Key")
# If ENTER is pressed
elif char == 10:
print("STOP")
finally:
#When 'q' is pressed and program ends
curses.nocbreak();screen.keypad(0);curses.echo()
curses.endwin()
The code above will above will print out the the direction of each directional key when that key is pressed. Curses comes with key Constance that allow you to access each key on the keyboard and give it a unique action. Note the command curses.KEY_UP . This references the curses constant for the Up directional key and once the key was pressed the action print(‘UP Key’) was given. Here is a list of the different Constants that come with the library.
This tutorial will show how to make a magic 8 ball program in python. This program will have the same functions as a magic 8 ball , the user will input a question and the 8-ball will generate a reply to the question. The user’s input will by retrieved by using input() . Here is…
This tutorial will show how to make a simple java program that will count how many day there are till Christmas. The package being used to handle the dates is java.time . If you are unfamiliar with this package here is a quick intro on how to use the package. The Christmas Count-down Clock code…
This tutorial will show how to create a time stamp with Java. Since Java does not have a built in package for handing dates and time, the package java.time will need to be imported. This package is an API for dates, times, instants, and durations. Here is a link to the java.time documentation if you…