I've noticed while learning programming that knowing maths gives you a definite edge on your peers. Not only in when you need to do calculations or that kind of stuff, but foremost in understanding things.
import random
import os
possible_Words = ['cat', 'dog', 'mouse']
tries = 10
word = random.sample(possible_Words, 1)
def word_Analysis():
wordList = list(word)
print wordList
word_Analysis()
Yeah you're right, in Python there's [lists], (tuples), and {sets}. I can't think of why I would want to use a tuple or set instead of a list though. What are they there for?A tuple is fixed size and immutable (i.e. cannot be changed once created) in Python, I thought. Strings are immutable as well, IIRC. Dunno if they are represented as a tuple of characters though.
A tuple is (a, b, c) and a list is [a, b, c], I think.
import random
possibleWords = ['augsburg', 'braunschweig', 'darmstadt', 'erfurt', 'schwerin', 'dortmund', 'karlsruhe', 'bielefeld', 'duisburg', 'frankfurt', 'heidelberg', 'mannheim', 'mainz', 'paderborn', 'passau', 'bremen', 'bonn', 'dresden', 'stuttgart', 'hannover', 'bochum', 'hamburg', 'berlin']
tries = 6
selectedWord = random.choice(possibleWords)
wordLen = len(selectedWord)
wordStatus = wordLen * ['_ ']
numberCorrect = 0
alreadyGuessed = []
def current_status():
print "\nCURRENT STATUS"
print "--------------"
print "Tries remaining: %d\n" % tries
print "WORD:\n"
print ''.join(wordStatus)
while tries > 0 and numberCorrect != wordLen:
current_status()
print "Type in a letter and press ENTER."
guess = raw_input('->')
if len(guess) == 1 and guess.isalpha() == True:
if selectedWord.find(guess) != -1 and guess not in alreadyGuessed:
print "Correct! The letter %s is in the word." % guess
alreadyGuessed.append(guess)
for i in range(wordLen):
if guess == selectedWord[i]:
wordStatus[i] = "%s " % guess
numberCorrect = numberCorrect + 1
elif guess in alreadyGuessed:
print "You already guessed that letter. Please choose another."
elif selectedWord.find(guess) == -1:
print "Sorry, the letter %s is not in the word." % guess
tries = tries - 1
else:
print "Invalid guess. Enter a single letter please."
if tries == 0:
current_status()
print "Sorry you lose! Your word was %s" %selectedWord
if numberCorrect == wordLen:
current_status()
print "Congratulations you've won! Your word was %s" % selectedWord
C#, VB.NET and Java add automatic garbage collection which makes it easier to make less mistakes. With C, you need to really know what you are doing, most programming languages allow you to shoot yourself in the foot, with C it's easy to blow your whole leg off. C++ allows you to blow your leg off and re-use the bullet.
Java. VB sucks (whether .NET or not).
Ok. Well I'm a computer science major however I am finishing my associates degree right now (only basic classes, nothing with computers).
Next semester I will start on my major and I have a choice between a seminar in JAVA or VB.NET. Which would you say is better?
I've always wondered people who identify themselves as the target group of those. "I'm dummy, so I should buy this!".
Can't comment on VB .NET as a language, though. I don't anticipate I'll be learning it anytime soon.
I'd say it depends on what you want to go into. If you like the idea of Windows programming, especially if you don't have experience there so far, VB.NET might be a good choice. Java is cross-platform and probably a better choice at the enterprise.
Nice one.
Tuples are more efficient than lists, but that's only important if your program is slow. And you only know if your program is slow when you run a profiler, follow the 3 rules of optimisation, from Djikstra:
1) Don't optimise
2) Don't optimise - yet
3) Only optimise something a profiler has told you is slow
That used to/still kinda is my greatest flaw.