1 Replies - 581 Views - Last Post: 25 December 2011 - 12:50 AM Rate Topic: -----

#1 merena  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 19-December 11

[PROBLEM] My upper-case program, p?

Posted 24 December 2011 - 02:30 AM

Hi guys python 2.7.2 with new my first upper-case program write. This is program have deficits. My program v0.1 sample code;

print "FMD upper-case - Max 4 char"
ch = raw_input("Enter verb: ")
if len(ch) == 1:
	print ch
	print ch.upper()
elif len(ch) == 2:
	print ch
	print ch.upper()
	print ch[0].upper()+ch[1]
	print ch[0]+ch[1].upper()
elif len(ch) == 3:
	print ch
	print ch.upper()
	print ch[0].upper()+ch[1]+ch[2]
	print ch[0].upper()+ch[1].upper()+ch[2] 
	print ch[0].upper()+ch[1]+ch[2].upper() 
	print ch[0]+ch[1].upper()+ch[2].upper() 
	print ch[0]+ch[1].upper()+ch[2] 
	print ch[0]+ch[1]+ch[2].upper()
elif len(ch) == 4: #sistem 1-3
	print ch
	print ch.upper()
	print ch[0]+ch[1].upper()+ch[2]+ch[3]
	print ch[0]+ch[1].upper()+ch[2].upper()+ch[3]
	print ch[0]+ch[1].upper()+ch[2]+ch[3].upper()
	print ch[0]+ch[1]+ch[2].upper()+ch[3].upper()
	print ch[0]+ch[1]+ch[2].upper()+ch[3]
	print ch[0]+ch[1]+ch[2]+ch[3].upper()
	print ch[0].upper()+ch[1].upper()+ch[2]+ch[3]
	print ch[0].upper()+ch[1].upper()+ch[2].upper()+ch[3]
	print ch[0].upper()+ch[1].upper()+ch[2]+ch[3].upper()
	print ch[0].upper()+ch[1]+ch[2].upper()+ch[3].upper()
	print ch[0].upper()+ch[1]+ch[2].upper()+ch[3]
	print ch[0].upper()+ch[1]+ch[2]+ch[3].upper()
        # max char length 15



Entered length 3 char: output -> 4 possibilities

After, this is program v0.1.2 but entered length 3 char -> 1 possibilities

#-*-coding: cp1254 -*-

import random
import math
YeniKelime = ""
kelimeler = []
kelime = raw_input("Entered verb: ")
if " " in kelime:
    print "do not space verb!"
    quit()
uzunluk = len(kelime)

permutasyon = math.factorial(uzunluk) / math.factorial(uzunluk-2)
i = 1
while i < permutasyon:
    for harf in kelime:
        sayi = random.randint(0,1)
        if sayi == 0:
            harf = harf.lower()
            YeniKelime += harf
        elif sayi == 1:
            harf = harf.upper()
            YeniKelime += harf
    kelimeler.append(YeniKelime)
    YeniKelime = ""
    i += 1

KelimeListesi = set(kelimeler)
print KelimeListesi
print len(KelimeListesi),"one possibility is found."


After more, this is program v0.1.3 but entered length 3 char -> 3 possibilities

#-*-coding: cp1254 -*-

import random
#import math
YeniKelime = ""
kelimeler = []
kelime = raw_input("Entered verb: ")
if " " in kelime:
    print "do not space verb!"
    quit()
uzunluk = len(kelime)

permutasyon = (uzunluk) * (uzunluk-1)
i = 1
while i < permutasyon:
    for harf in kelime:
        sayi = random.randint(0,1)
        if sayi == 0:
            harf = harf.lower()
            YeniKelime += harf
        elif sayi == 1:
            harf = harf.upper()
            YeniKelime += harf
    kelimeler.append(YeniKelime)
    hepsibuyuk = kelime.upper()
    hepsikucuk = kelime.lower()
    
    YeniKelime = ""
    i += 1
   
    kelimeler.append(hepsibuyuk)
    kelimeler.append(hepsikucuk)
   
KelimeListesi = set(kelimeler)
print KelimeListesi
print len(KelimeListesi),"one possibility is found."


With the same logic as the first release does not consist of 4 possibilities. Where is the error I'm doing for 4 possibilities?

Thanks guys...

This post has been edited by Simown: 24 December 2011 - 03:47 AM
Reason for edit:: added code tags. Please use code tags for all of your code!


Is This A Good Question/Topic? 0
  • +

Replies To: [PROBLEM] My upper-case program, p?

#2 cupidvogel  Icon User is offline

  • D.I.C Addict

Reputation: 31
  • View blog
  • Posts: 593
  • Joined: 25-November 10

Re: [PROBLEM] My upper-case program, p?

Posted 25 December 2011 - 12:50 AM

Forget second and third parts of your code, the first part drove me nuts. Why are you printing the words by concatenating each character converted to upper-case??? Just convert the entire god-damned word at one using

print ch.upper()



Secondly, explain the objective of the 2nd and 3rd pieces of code. I can't understand what are they trying to achieve. And thirdly, change the way you name your posts. Don't name them like My program output in space problem, My factorial function error! or My upper-case program, p?. Give them descriptive names, and clearly state what kind of error or problem you are facing.

This post has been edited by cupidvogel: 25 December 2011 - 12:51 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1