Code to let the user know what
to wear and ask the weather.
reset
$a = ask "Is it: rainy or sunny?"
# Check user input
if $a == "rainy" {
message "Wear a coat"
}
else {
message "Wear shorts, you fatty."
}
Code to make a square
according to the user less than
50
reset
$a = ask "Write the length of the square less than 50, you fatty."
if $a > 50 {
repeat 4 { fw $a tr 90}
}
else {
message "Stop being a fatty and write the correct value."
Code to check Values > or <
reset
$a = ask "Input a number."
if $a > 10 {
message "Your value is greater than 10."
}
else {
message "Your value is less than 10"
}
Code to ask the User to make a
circle using ask command
reset
$a = ask "Would you like to draw a circle?"
if $a == "yes" {
repeat 90 {fw 5 tr 4
}
}
else {
message "You should've written yes, you fatty!"
}
Code to use the For loop number
line
reset
for $a = 10 to 15 {
print $a
pu
fw 15
}
Code to use the While loop
reset
$a = 1
while $a < 10 {
fw 20
print $a
$a = $a + 2
}
How to create a square using
Learn command
reset
learn square $a {
repeat 4 {fw $a tr 90}
}
square 130
square 160
square 140
Adding natural number
reset
learn sum $x {
$a = 0
for $n = 1 to $x {
$a = $a + $n }
return $a}
fontsize 50
print "Sum = " + sum 6
How to make a rectangle
reset
repeat 2 {fw 20 tr 90 fw 50 tr 90}
Making a rectangle using learn
command $l and $b
reset
learn rectangle $l, $b {
repeat 2 {fw $l tr 90 fw $b tr 90}
}
pw 5
rectangle 50, 100
rectangle 20, 60
Code for circle using Learn
reset
learn box $x {
repeat 36 {
forward $x
tr 10 } }
box 2
Code to draw hexagonal maze
reset
repeat 60 { repeat 6 { fw 100 tr 60 }
fw 5 tr 6 }
go 0,0
Code to draw a circle kind of
design using for loop
reset
for $a = 5 to 35 step 5 {
repeat 36 {fw $a tr 10}
}
Code for going backwards form
10 by 3s
reset
go 5,5
fontsize 30
for $a = 10 to 1 step -3 {
print $a backward 30}
sh
Code to display odd numbers in
the range of 1-10 using the while
loop
reset
$a = 1
while $a <= 10 {
print $a
fw 15
$a = $a + 2}
Code to display odd numbers in
the range of 1-10 using the for
loop
reset
$a = 1
for $a = 1 to 10 step 2 {
print $a
fw 15
}
Code that asks the user to add a
number and display its table up
to 10 using the for loop
reset
$a = ask "Please input a number"
for $i = 1 to 10 {
print $a * $i
fw 15}
Code that asks the user to add a
number and display its table up
to 10 using the while loop
reset
$a = ask "Please input a number"
$i = 1
while $i <= 10 {
print $a * $i
fw 15
$i = $i + 1}
Create a command square with
one input $length using Learn
command
reset
learn square $length {
repeat 4 {fw $length tr 90}
}
square 50
square 90
Code that asks you to enter the
size of circle using learn
command.
reset
learn circle $a {
repeat 36 { fw $a tr 10 }}
$j = ask "Enter the size of the circle you want to draw."
Circle $j
Adding natural numbers easier
version
reset
learn sumofnaturalnumbers $limit {
$sum = 0
for $n = 1 to $limit {
$sum = $sum + $n }
return $sum}
fontsize 50
print "Sum = " + sum 6
MS SMALL BASIC
Code to find out if a number is
divisible by 3
TextWindow.WriteLine("Enter a number")
number = TextWindow.ReadNumber()
x = Math.Remainder(number, 3)
If (x = 0) Then
TextWindow.WriteLine("It is divisible by 3")
Else
TextWindow.WriteLine("It is not divisible by 3")
EndIf
Code to find out what your grade
is
TextWindow.WriteLine("Enter the total marks")
marks= TextWindow.ReadNumber()
If (marks > 450) Then
Grade = "A"
Elseif (marks > 400) Then
Grade = "B"
Elseif (marks > 350) Then
Grade = "C"
Elseif (marks > 300) Then
Grade = "D"
Else
Grade = "E"
EndIf
TextWindow.WriteLine("Grade = " + Grade)
Print the squares and cubes of
numbers (MS SMALL BASIC)
i = 5
TextWindow.WriteLine("Number " + "Square " + "Cube")
While i <= 9
s = i * i
c = i * i * i
TextWindow.Write (" " + i)
TextWindow.Write (" " + s)
TextWindow.WriteLine (" " + c)
i = i + 1
EndWhile
Print the timetable of a number
till 10
TextWindow.WriteLine ("Enter a number")
j = TextWindow.ReadNumber()
For i = 1 To 10
p = i * j
TextWindow.WriteLine (i + "*" + j + " = " + p)
EndFor
Percentage of attendance
i = 0
While i > -1
TextWindow.WriteLine ("How many days were in that month?")
D = TextWindow.ReadNumber ()
TextWindow.WriteLine ("How many days did you come to school in
that month")
A = TextWindow.ReadNumber()
P = A/D * 100
TextWindow.WriteLine ("The percentange of the student coming
to school in a particular month is " + P)
TextWindow.WriteLine ("If you don't want to continue enter -1
else enter any other number")
i = TextWindow.ReadNumber()
EndWhile
Change F to Celsius
TextWindow.WriteLine ("Enter the upper limit of the temeperature in F")
upperlimit = TextWindow.ReadNumber() TextWindow.WriteLine ("Enter the lower
limit of the temperature in F") lowerlimit = TextWindow.ReadNumber()
TextWindow.WriteLine ("Fahrenheit" + " " + "Celsius") For Fahrenheit = lowerlimit
To upperlimit Celsius = (Fahrenheit - 32) * 5/9 TextWindow.WriteLine (Fahrenheit
+ " " + Celsius) EndFo
Drawing lots of circles
GraphicsWindow.BackgroundColor = "Orange"
GraphicsWindow.PenColor = "White"
GraphicsWindow.PenWidth = 1
GraphicsWindow.Width = 400
GraphicsWindow.Height = 400
For I = 1 To 200 Step 5
GraphicsWindow.DrawEllipse(200 - I, 200 - I, I * 2, I * 2)
EndFor
Draw lots of squares
GraphicsWindow.BackgroundColor = "Maroon"
GraphicsWindow.PenColor = "White"
GraphicsWindow.PenWidth = 1
GraphicsWindow.Width = 400
GraphicsWindow.Height = 400
For I = 1 To 200 Step 5
GraphicsWindow.DrawRectangle(200 - I, 200 - I, I * 2, I * 2)
EndFor
Visual Basic
How to find the net amount
Public Class Form1
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim Amount, Discount, NetAmount As Single
Amount = Val(TextBox1.Text)
Discount = 15 / 100 * Amount
NetAmount = Amount - Discount
TextBox2.Text = Discount
TextBox3.Text = NetAmount
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Close()
End Sub
End Class
Code to show the cubes and
squares
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
End Sub
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
TextBox2.Text = Val(TextBox1.Text) ^ 2
TextBox3.Text = Val(TextBox1.Text) ^ 3
End Sub
End Class
Convert F to C
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox2.Text = (Val(TextBox1.Text) - 32) * 5 / 9
End Sub
End Class
Find area and perimeter
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox3.Text = Val(TextBox1.Text) * Val(TextBox2.Text)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
TextBox4.Text = 2 * (Val(TextBox1.Text) + Val(TextBox2.Text))
End Sub
End Class
Find average and total marks
Imports System.Numerics
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox4.Text = Val(TextBox1.Text) + Val(TextBox2.Text) + Val(TextBox3.Text)
TextBox5.Text = Val(TextBox4.Text) / 3
End Sub
End Class
Convert cm to inch and feet
Imports System.Numerics
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox2.Text = Val(TextBox1.Text) / 2.54
TextBox3.Text = Val(TextBox1.Text) / 30.48
End Sub
End Class
PYTHO
N
Write a program to check
whether a person is eligible for
voting or not (accept input from
user)
age = int (input("Enter your age:"))
if age >= 18:
print ("You are eligible to vote ")
else :
print ("Grow up, kid")
Write a program to check
whether a number input by the
user is even or not (accept input
from user)
number = int(input("Enter a number : "))
if number % 2 == 0 :
print("The number is even")
else :
print ("The number is odd")
Write a program to check
whether a number input by the
user is divisible by 7 or not
(accept input from user)
number = int(input("Enter a number : "))
if number % 7 == 0 :
print ("It's divisible by 7")
else :
print ("It's not divisible by 7")
Write a program to check
whether number input by the
user is a multiple of 5, and if it is,
display “Hello”, otherwise
display “Bye”.
number = int(input("Enter a number : "))
if number % 5 == 0 :
print ("Hello")
else :
print ("Bye")
Write a program to calculate the
electricity bill (accept number of
unit from user) according to the
following criteria:
unit = int(input("Enter the units you have used the electricity for :"))
price = 0
if unit <= 100 :
price = unit * 0
if unit > 100 and unit < 200 :
price = (unit - 100) * 5
if unit > 200 :
price = 500 + (unit - 200) * 10
print (price)
marks = int(input("Enter your marks : "))
if marks > 90 :
grade = "A"
elif marks > 80 and marks <= 90:
grade = "B"
elif marks >= 60 and marks <= 80:
grade = "C"
else :
grade = "D"
print(grade)
Code to use the while loop to
print numbers from 1 to 5 in
python.
x=0
while x <= 5 :
print (x)
x += 1
Code to use range starting from
2 and printing numbers till 6
with increment of 1
for i in range (2,7,1)
print (i)
Code to use range by printing
numbers in backwards from 10
to 3 decreasing in 2s
for i in range (10,2,-2)
print (i)
Code to make a list and print all
the elements one by one using
For loop
fruits = ["bananas", "apples", "oranges", “kiwis”, “grapes”]
for fruit in fruits:
print(fruit)
Code to make a list and print all
the elements containing the
brackets
fruits = ["bananas", "apples", "oranges", “kiwis”, “grapes”]
print(fruits)
Code to print last three
elements in a list using for loop
fruits = ["bananas", "apples", "oranges", “kiwis”, “grapes”]
for fruit in fruits:
print(fruit [-3:]) or print(fruit [3:])
Code to print last three elements
in a list using for loop
fruits = ["bananas", "apples", "oranges", “kiwis”, “grapes”]
for fruit in fruits:
print(fruits [:3] )
Code to print numbers from one
to ten using while loop
i=1
while i <= 10:
print (i)
i=i+1
Write a program that asks the
user for a number and displays
its table up to ten using while
loop
number = int(input("Enter a number : "))
multiplier = 1
while multiplier <= 10:
result = number * multiplier
multiplier = multiplier + 1
print (result)
Write a program that asks the
user for a number and displays
its table up to ten using for loop
number = int(input("Enter a number : "))
for multiplier in range(1,11):
result = number * multiplier
multiplier = multiplier + 1
print (result)
Write a program that asks the
length of a square and prints its
area
length = int(input("Enter the length of a square : "))
area = length * length
print ("The are of the square is : " + str(area))
Code to ask a number and print
its multiples until the user
doesn’t press the number 1
using while loop
nnumber = 1
while nnumber == 1:
number = int(input("Enter a number : "))
multiplier = 1
while multiplier <= 10:
result = number * multiplier
print (result)
multiplier = multiplier + 1
nnumber = int(input("Do you want to find the multiples of another number; If yes, press 1"))
Code to ask user for two
numbers and ask if they want to
add,subtract divide or multiply
using while loop, if and elif and
else statement (mini calculator)
nnumber = 5
while nnumber == 5:
x = int(input("Enter the first number : "))
y = int(input("Enter the second number : "))
jinput = int(input( "If you want to add the numbers, press on one. \nIf you want to subtract the
numbers, press two.\nIf you want to multiply the numbers, press three. \nIf you want to divide the
numbers, press four." ))
if jinput==1 :
result = x + y
print (str(x) + "+" + str(y) + "=" + str(result))
elif jinput == 2 :
result = x - y
print (str(x) + "-" + str(y) + "=" + str(result))
elif jinput == 3 :
result = x/y
print (str(x) + "/" + str(y) + "=" + str(result))
elif jinput == 4:
result = x * y
print (str(x) + "*" + str(y) + "=" + str(result))
else :
print ("Input is invalid")
nnumber : int(input("Do you want to continue using other numbers? If yes, press 5"))
Note: /n is used to start a new line
Code to draw a line of 35 dashes
print ("-" * 35 )
Code to print 9 times
Print (“a” * 9)
Code that asks the user if there
were any visitors and will work
while the input is Y (using while
loop)
total = 0
visitor = input("Is there a visitor? Y/N : ")
while visitor == "Y":
total += 1
visitor = input("Is there a visitor? Y/N : ")
print (total)
Code that asks the user #of
visits and will work while the
input is greater than 1 (using
while loop)
total = 0
visits = int(input("Number of visits : "))
while visits > -1:
total += visits
visits = int(input("number of visits : "))
print (total)
Code that asks the user #of
visits for 20 times (using for
loop)
total = 0
for i in range (20):
visits = int(input("number of visits : "))
total += visits
print (total)
A BETTER VERSION
print("B I R D V I S I T O R S")
print ("=" * 24)
print ("Count the number of visits to the feeder. Time yourself.\n At the end of each minute, enter
the number. \n When you type -1, the program will stop. \n \n ")
total = 0
visits = int(input("Number of visits : "))
while visits > -1:
total += visits
visits = int(input("number of visits : "))
print ("-" * 24)
print ("The total number of visits is ", total)
Code that asks the user #of
visits and will work while the
input is greater than -1 and
calculates the average (using
while loop)
print("B I R D V I S I T O R S")
print ("=" * 24)
print ("Count the number of visits to the feeder. Time yourself.\n At the end of each minute, enter
the number. \n When you type -1, the program will stop. \n \n ")
total = 0
counter = 0
visits = int(input("Number of visits : "))
while visits > -1:
counter += 1
total += visits
visits = int(input("Number of visits : "))
print ("-" * 24)
print ("The total number total number of visits are : ", total)
average = total/counter
print ("The average value of visits in a minute is ", average)