Exercise 4: Variables And Names
inspired by http://learnpythonthehardway.org/book/ex4.html
using System;
public class Test
{
public static void Main()
{
int cars, drivers, cars_not_driven;
cars = 100;
drivers = 30;
cars_not_driven = cars - drivers;
Console.WriteLine("There will be " + cars_not_driven + " empty cars today.");
}
}
Monday, March 21, 2016
Exercise 3: Numbers and Math
Exercise 3: Numbers and Math
inspired by http://learnpythonthehardway.org/book/ex3.html
using System;
public class Test
{
public static void Main()
{
Console.WriteLine("I will now count my chickens:");
Console.WriteLine("Hens"+ (26 + 30 / 5) );
Console.WriteLine("Roosters"+ (100 - 25 * 3 % 4) );
Console.WriteLine("Now I will count the eggs:");
Console.WriteLine(3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6);
Console.WriteLine("Is it true that 3 + 2 < 5 - 7?");
Console.WriteLine(3 + 2 < 5 - 7);
Console.WriteLine("What is 3 + 2? "+ (3 + 2) );
Console.WriteLine("What is 5 - 7? "+ (5 - 7) );
Console.WriteLine("Oh, that's why it's False.");
Console.WriteLine("How about some more.");
Console.WriteLine("Is it greater?"+ (5 > -2) );
Console.WriteLine("Is it greater or equal?"+ (5 >= -2) );
Console.WriteLine("Is it less or equal?"+ (5 <= -2) );
}
}
inspired by http://learnpythonthehardway.org/book/ex3.html
using System;
public class Test
{
public static void Main()
{
Console.WriteLine("I will now count my chickens:");
Console.WriteLine("Hens"+ (26 + 30 / 5) );
Console.WriteLine("Roosters"+ (100 - 25 * 3 % 4) );
Console.WriteLine("Now I will count the eggs:");
Console.WriteLine(3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6);
Console.WriteLine("Is it true that 3 + 2 < 5 - 7?");
Console.WriteLine(3 + 2 < 5 - 7);
Console.WriteLine("What is 3 + 2? "+ (3 + 2) );
Console.WriteLine("What is 5 - 7? "+ (5 - 7) );
Console.WriteLine("Oh, that's why it's False.");
Console.WriteLine("How about some more.");
Console.WriteLine("Is it greater?"+ (5 > -2) );
Console.WriteLine("Is it greater or equal?"+ (5 >= -2) );
Console.WriteLine("Is it less or equal?"+ (5 <= -2) );
}
}
Exercise 2: Comments
Exercise 2: Comments
inspired by http://learnpythonthehardway.org/book/ex2.html
using System;
public class Test
{
public static void Main()
{
// A comment, this is so you can read your program later.
// Anything after the // is ignored by C#.
Console.WriteLine("I could have code like this."); // and the comment after is ignored
// Console.WriteLine("This won't run.");
Console.WriteLine("This will run.");
}
}
inspired by http://learnpythonthehardway.org/book/ex2.html
using System;
public class Test
{
public static void Main()
{
// A comment, this is so you can read your program later.
// Anything after the // is ignored by C#.
Console.WriteLine("I could have code like this."); // and the comment after is ignored
// Console.WriteLine("This won't run.");
Console.WriteLine("This will run.");
}
}
Subscribe to:
Posts (Atom)