eduka projekti kirjeldus
import random as r
words_hard = [
"table", "star", "root", "flat", "turtle", "fish", "goat", "rocket",
"dragon", "power", "source", "program", "wheel", "candle", "dog", "cat", "branch"
]
words_easy = [
"dragonborn", "monosaccharide", "disposable", "environment",
"implementation", "disorientation", "carbohydrate", "disrespectful", "dominant"
]
difficulty = input("Please select difficulty('h' for 'hard' and 'e' for 'easy'): ")
if difficulty == 'h':
words = words_hard
elif difficulty == 'e':
words = words_easy
else:
raise ValueError("Not allowed input")
word = r.choice(words)
guesses = len(word)
guess_word = ["*"] * len(word)
while True:
print(f"\nGuesses left: {guesses}")
print(f"The word is: {''.join(guess_word)}")
char = input("Please enter single character: ")
if char in word:
for i in range(len(word)):
guess_word[i] = char if word[i] == char else guess_word[i]
else:
print(f"The character {char} is not in the word!")
guesses -= 1
if "".join(guess_word) == word:
print("\nYou won!")
print(f"The word is: {word}")
break
if guesses == 0:
print("\nYou lost!")
print(f"The word was {word}")
break
Projekt – TallinnaRakenduslikKolledž
Projekti ees märk on luua algeline andmebaas kooli jaoks
Näide koodist:
See on koodi mudel, see defineerib Delinquents klassi, mis sisaldab teavet isiku kohta.
using System.ComponentModel.DataAnnotations;
namespace TallinnaRakenduslikKolledz.Models
{
public class Delinquents
{
[Key]
public int DelinquentsId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public enum Violation
{
Smoking, Graffiti, Gooning, Gangviolents, Makingmeth
}
public string Details { get; set; }
public bool Instructor { get; set; }
}
}
Näide koodist:
See on näide MVC koodi struktuur
MVC korraldab koodi ja rakenduse mitmeks omavahel ühendatud komponendiks.
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using Microsoft.Identity.Client;
using Microsoft.IdentityModel.Tokens;
using TallinnaRakenduslikKolledz.Data;
using TallinnaRakenduslikKolledz.Models;
namespace TallinnaRakenduslikKolledz.Controllers
{
public class CoursesController : Controller
{
private readonly SchoolContext _context;
public CoursesController(SchoolContext context)
{
_context = context;
}
public IActionResult Index()
{
var courses = _context.Courses.Include(c => c.Department)
.AsNoTracking();
return View(courses);
}
[HttpGet]
public IActionResult Create()
{
PopulateDepartmentsDropDownList();
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(Course course)
{
if (ModelState.IsValid)
{
_context.Add(course);
await _context.SaveChangesAsync();
PopulateDepartmentsDropDownList(course.DepartmentID);
}
return RedirectToAction();
}
public async Task<IActionResult> Delete(int? id)
{
if (id == null || _context.Courses == null)
{
return NotFound();
}
var courses = await _context.Courses
.Include(c => c.Department)
.AsNoTracking()
.FirstOrDefaultAsync(mbox => mbox.CourseId == id);
if (courses == null)
{
return NotFound();
}
return View(courses);
}
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(int id)
{
if (_context.Courses == null)
{
return NotFound();
}
var course = await _context.Courses.FindAsync(id);
if (course != null)
{
_context.Courses.Remove(course);
}
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
private void PopulateDepartmentsDropDownList(object selectedDepartment = null)
{
var departmentsQuery = from d in _context.Departments
orderby d.Name
select d;
ViewBag.DepartmentID = new SelectList(departmentsQuery.AsNoTracking(),
"DepartmentID", "Name", selectedDepartment);
}
}
}